diff options
| author | Yingwei Zheng <dtcxzyw2333@gmail.com> | 2025-04-11 10:51:08 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-04-11 10:51:08 +0800 |
| commit | 04c38981a9ce3e6225669c0e41cab947e3e7989f (patch) | |
| tree | 11f9ae63e6444085c8329c724fd93aa176f722b0 /clang/lib/CodeGen/CGClass.cpp | |
| parent | f40001372b54ce68507f36b600f798e832478e16 (diff) | |
[Clang][CodeGen] Do not set inbounds flag in `EmitMemberDataPointerAddress` when the base pointer is null (#130952)
See also https://github.com/llvm/llvm-project/pull/130734 for the
original motivation.
This pattern (`container_of`) is also widely used by real-world
programs.
Examples:
https://github.com/llvm/llvm-project/blob/1d89d7d5d76e391b035f50343e2a4890506c6f2b/llvm/include/llvm/IR/SymbolTableListTraits.h#L77-L87
https://github.com/nodejs/node/blob/a2a53cb728ec5f776ac16879ce0f480a8e838320/src/util-inl.h#L134-L137
https://github.com/search?q=*%29nullptr-%3E*&type=code
Diffstat (limited to 'clang/lib/CodeGen/CGClass.cpp')
| -rw-r--r-- | clang/lib/CodeGen/CGClass.cpp | 15 |
1 files changed, 6 insertions, 9 deletions
diff --git a/clang/lib/CodeGen/CGClass.cpp b/clang/lib/CodeGen/CGClass.cpp index c683dbb0af82..0f2422a6a665 100644 --- a/clang/lib/CodeGen/CGClass.cpp +++ b/clang/lib/CodeGen/CGClass.cpp @@ -147,16 +147,13 @@ Address CodeGenFunction::LoadCXXThisAddress() { /// Emit the address of a field using a member data pointer. /// /// \param E Only used for emergency diagnostics -Address -CodeGenFunction::EmitCXXMemberDataPointerAddress(const Expr *E, Address base, - llvm::Value *memberPtr, - const MemberPointerType *memberPtrType, - LValueBaseInfo *BaseInfo, - TBAAAccessInfo *TBAAInfo) { +Address CodeGenFunction::EmitCXXMemberDataPointerAddress( + const Expr *E, Address base, llvm::Value *memberPtr, + const MemberPointerType *memberPtrType, bool IsInBounds, + LValueBaseInfo *BaseInfo, TBAAAccessInfo *TBAAInfo) { // Ask the ABI to compute the actual address. - llvm::Value *ptr = - CGM.getCXXABI().EmitMemberDataPointerAddress(*this, E, base, - memberPtr, memberPtrType); + llvm::Value *ptr = CGM.getCXXABI().EmitMemberDataPointerAddress( + *this, E, base, memberPtr, memberPtrType, IsInBounds); QualType memberType = memberPtrType->getPointeeType(); CharUnits memberAlign = |
