diff options
author | Sanjay Patel <spatel@rotateright.com> | 2018-01-19 15:14:51 +0000 |
---|---|---|
committer | Sanjay Patel <spatel@rotateright.com> | 2018-01-19 15:14:51 +0000 |
commit | 372c3f1f99dd98627c0bf0e2a1d2c0f2ed8a6ce9 (patch) | |
tree | 2d289703abc66c72b4647149e5d303cc28240735 /clang/lib/CodeGen/CGClass.cpp | |
parent | eb74ab8633d63fefceb9c1ab5b7fbf2b8d9779de (diff) | |
download | bcm5719-llvm-372c3f1f99dd98627c0bf0e2a1d2c0f2ed8a6ce9.tar.gz bcm5719-llvm-372c3f1f99dd98627c0bf0e2a1d2c0f2ed8a6ce9.zip |
[CodeGenCXX] annotate a GEP to a derived class with 'inbounds' (PR35909)
The standard says:
[expr.static.cast] p11: "If the prvalue of type “pointer to cv1 B” points to a B
that is actually a subobject of an object of type D, the resulting pointer points
to the enclosing object of type D. Otherwise, the behavior is undefined."
Therefore, the GEP must be inbounds.
This should solve the failure to optimize away a null check shown in PR35909:
https://bugs.llvm.org/show_bug.cgi?id=35909
Differential Revision: https://reviews.llvm.org/D42249
llvm-svn: 322950
Diffstat (limited to 'clang/lib/CodeGen/CGClass.cpp')
-rw-r--r-- | clang/lib/CodeGen/CGClass.cpp | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/clang/lib/CodeGen/CGClass.cpp b/clang/lib/CodeGen/CGClass.cpp index a6915071ec1..593d6152c8b 100644 --- a/clang/lib/CodeGen/CGClass.cpp +++ b/clang/lib/CodeGen/CGClass.cpp @@ -406,8 +406,8 @@ CodeGenFunction::GetAddressOfDerivedClass(Address BaseAddr, // Apply the offset. llvm::Value *Value = Builder.CreateBitCast(BaseAddr.getPointer(), Int8PtrTy); - Value = Builder.CreateGEP(Value, Builder.CreateNeg(NonVirtualOffset), - "sub.ptr"); + Value = Builder.CreateInBoundsGEP(Value, Builder.CreateNeg(NonVirtualOffset), + "sub.ptr"); // Just cast. Value = Builder.CreateBitCast(Value, DerivedPtrTy); |