r196545 - [ms-cxxabi] bitcast to i8* to deref a data member pointer

Reid Kleckner reid at kleckner.net
Thu Dec 5 14:44:08 PST 2013


Author: rnk
Date: Thu Dec  5 16:44:07 2013
New Revision: 196545

URL: http://llvm.org/viewvc/llvm-project?rev=196545&view=rev
Log:
[ms-cxxabi] bitcast to i8* to deref a data member pointer

This was causing us to miscompile
llvm::SymbolTableListTraits::getListOwner(), which uses data member
pointers.

Modified:
    cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp
    cfe/trunk/test/CodeGenCXX/microsoft-abi-member-pointers.cpp

Modified: cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp?rev=196545&r1=196544&r2=196545&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp (original)
+++ cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp Thu Dec  5 16:44:07 2013
@@ -1691,6 +1691,11 @@ MicrosoftCXXABI::EmitMemberDataPointerAd
     Base = AdjustVirtualBase(CGF, RD, Base, VirtualBaseAdjustmentOffset,
                              VBPtrOffset);
   }
+
+  // Cast to char*.
+  Base = Builder.CreateBitCast(Base, Builder.getInt8Ty()->getPointerTo(AS));
+
+  // Apply the offset, which we assume is non-null.
   llvm::Value *Addr =
     Builder.CreateInBoundsGEP(Base, FieldOffset, "memptr.offset");
 

Modified: cfe/trunk/test/CodeGenCXX/microsoft-abi-member-pointers.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/microsoft-abi-member-pointers.cpp?rev=196545&r1=196544&r2=196545&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/microsoft-abi-member-pointers.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/microsoft-abi-member-pointers.cpp Thu Dec  5 16:44:07 2013
@@ -537,3 +537,23 @@ int A::*reinterpret(int C::*mp) {
 }
 
 }
+
+namespace Test3 {
+// Make sure we cast 'this' to i8* before using GEP.
+
+struct A {
+  int a;
+  int b;
+};
+
+int *load_data(A *a, int A::*mp) {
+  return &(a->*mp);
+// CHECK-LABEL: define i32* @"\01?load_data at Test3@@YAPAHPAUA at 1@PQ21 at H@Z"{{.*}}  {
+// CHECK:    %[[a:.*]] = load %"struct.Test3::A"** %{{.*}}, align 4
+// CHECK:    %[[mp:.*]] = load i32* %{{.*}}, align 4
+// CHECK:    %[[a_i8:.*]] = bitcast %"struct.Test3::A"* %[[a]] to i8*
+// CHECK:    getelementptr inbounds i8* %[[a_i8]], i32 %[[mp]]
+// CHECK: }
+}
+
+}





More information about the cfe-commits mailing list