r199168 - [ms-abi] Report VBPtrOffset correctly

Warren Hunt whunt at google.com
Mon Jan 13 16:31:30 PST 2014


Author: whunt
Date: Mon Jan 13 18:31:30 2014
New Revision: 199168

URL: http://llvm.org/viewvc/llvm-project?rev=199168&view=rev
Log:
[ms-abi] Report VBPtrOffset correctly

Although VBPtrs were being placed correctly by the ms-abi layout engine, 
their offsets were being improperly reported to the ASTRecordLayout 
builder due to a bug.  This patch fixes that and fixes the test cases to 
use the correct values.
y

Modified:
    cfe/trunk/lib/AST/RecordLayoutBuilder.cpp
    cfe/trunk/test/CodeGenCXX/microsoft-abi-member-pointers.cpp
    cfe/trunk/test/CodeGenCXX/microsoft-abi-vtables-virtual-inheritance-vtordisps.cpp
    cfe/trunk/test/CodeGenCXX/virtual-base-cast.cpp

Modified: cfe/trunk/lib/AST/RecordLayoutBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/RecordLayoutBuilder.cpp?rev=199168&r1=199167&r2=199168&view=diff
==============================================================================
--- cfe/trunk/lib/AST/RecordLayoutBuilder.cpp (original)
+++ cfe/trunk/lib/AST/RecordLayoutBuilder.cpp Mon Jan 13 18:31:30 2014
@@ -2341,6 +2341,10 @@ MicrosoftRecordLayoutBuilder::layoutNonV
   // Set our VBPtroffset if we know it at this point.
   if (!HasVBPtr)
     VBPtrOffset = CharUnits::fromQuantity(-1);
+  else if (SharedVBPtrBase) {
+    const ASTRecordLayout &Layout = Context.getASTRecordLayout(SharedVBPtrBase);
+    VBPtrOffset = Bases[SharedVBPtrBase] + Layout.getVBPtrOffset();
+  }
 }
 
 void MicrosoftRecordLayoutBuilder::layoutNonVirtualBase(
@@ -2444,13 +2448,8 @@ MicrosoftRecordLayoutBuilder::layoutZero
 }
 
 void MicrosoftRecordLayoutBuilder::injectVBPtr(const CXXRecordDecl *RD) {
-  if (!HasVBPtr)
+  if (!HasVBPtr || SharedVBPtrBase)
     return;
-  if (SharedVBPtrBase) {
-    const ASTRecordLayout &Layout = Context.getASTRecordLayout(SharedVBPtrBase);
-    VBPtrOffset = Bases[SharedVBPtrBase] + Layout.getVBPtrOffset();
-    return;
-  }
   // Inject the VBPointer at the injection site.
   CharUnits InjectionSite = VBPtrOffset;
   // But before we do, make sure it's properly aligned.

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=199168&r1=199167&r2=199168&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/microsoft-abi-member-pointers.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/microsoft-abi-member-pointers.cpp Mon Jan 13 18:31:30 2014
@@ -95,7 +95,7 @@ void (UnspecSingle::*us_f_mp)() = &Unspe
 // CHECK: @"\01?v_f_mp at Const@@3P8Virtual@@AEXXZQ2@" =
 // CHECK:   global { i8*, i32, i32 } { i8* bitcast ({{.*}} @"\01?foo at Virtual@@QAEXXZ" to i8*), i32 0, i32 0 }, align 4
 // CHECK: @"\01?u_f_mp at Const@@3P8Unspecified@@AEXXZQ2@" =
-// CHECK:   global { i8*, i32, i32, i32 } { i8* bitcast ({{.*}} @"\01?foo at Unspecified@@QAEXXZ" to i8*), i32 0, i32 20, i32 0 }, align 4
+// CHECK:   global { i8*, i32, i32, i32 } { i8* bitcast ({{.*}} @"\01?foo at Unspecified@@QAEXXZ" to i8*), i32 0, i32 12, i32 0 }, align 4
 // CHECK: @"\01?us_f_mp at Const@@3P8UnspecSingle@@AEXXZQ2@" =
 // CHECK:   global { i8*, i32, i32, i32 } { i8* bitcast ({{.*}} @"\01?foo at UnspecSingle@@QAEXXZ" to i8*), i32 0, i32 0, i32 0 }, align 4
 }
@@ -167,7 +167,7 @@ void EmitNonVirtualMemberPointers() {
 // CHECK:     { i8* bitcast (void (%{{.*}}*)* @"\01?foo at Virtual@@QAEXXZ" to i8*), i32 0, i32 0 },
 // CHECK:     { i8*, i32, i32 }* %{{.*}}, align 4
 // CHECK:   store { i8*, i32, i32, i32 }
-// CHECK:     { i8* bitcast (void (%{{.*}}*)* @"\01?foo at Unspecified@@QAEXXZ" to i8*), i32 0, i32 20, i32 0 },
+// CHECK:     { i8* bitcast (void (%{{.*}}*)* @"\01?foo at Unspecified@@QAEXXZ" to i8*), i32 0, i32 12, i32 0 },
 // CHECK:     { i8*, i32, i32, i32 }* %{{.*}}, align 4
 // CHECK:   store { i8*, i32, i32, i32 }
 // CHECK:     { i8* bitcast (void (%{{.*}}*)* @"\01?foo at UnspecWithVBPtr@@QAEXXZ" to i8*),

Modified: cfe/trunk/test/CodeGenCXX/microsoft-abi-vtables-virtual-inheritance-vtordisps.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/microsoft-abi-vtables-virtual-inheritance-vtordisps.cpp?rev=199168&r1=199167&r2=199168&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/microsoft-abi-vtables-virtual-inheritance-vtordisps.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/microsoft-abi-vtables-virtual-inheritance-vtordisps.cpp Mon Jan 13 18:31:30 2014
@@ -264,7 +264,7 @@ struct H : Z, A {
 
   // VTABLE-EXTENDED-H: VFTable for 'V1' in 'simple::A' in 'extended::A' in 'extended::H' (2 entries).
   // VTABLE-EXTENDED-H-NEXT: 0 | void simple::A::f()
-  // VTABLE-EXTENDED-H-NEXT:     [this adjustment: vtordisp at -4, vbptr at 4 to the left,
+  // VTABLE-EXTENDED-H-NEXT:     [this adjustment: vtordisp at -4, vbptr at 8 to the left,
   // VTABLE-EXTENDED-H-NEXT:      vboffset at 8 in the vbtable, 8 non-virtual]
 
   // MANGLING-DAG: @"\01?f at A@simple@@$R477PPPPPPPM at 7AEXXZ"

Modified: cfe/trunk/test/CodeGenCXX/virtual-base-cast.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/virtual-base-cast.cpp?rev=199168&r1=199167&r2=199168&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/virtual-base-cast.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/virtual-base-cast.cpp Mon Jan 13 18:31:30 2014
@@ -77,13 +77,13 @@ BB* d() { return y; }
 // Same as 'c' except the vbptr offset is 4, changing the initial GEP and the
 // final add.
 // MSVC: @"\01?d@@YAPAUBB@@XZ"() [[NUW:#[0-9]+]] {
-// MSVC:   %[[vbptr_off:.*]] = getelementptr inbounds i8* {{.*}}, i32 12
+// MSVC:   %[[vbptr_off:.*]] = getelementptr inbounds i8* {{.*}}, i32 4
 // MSVC:   %[[vbptr:.*]] = bitcast i8* %[[vbptr_off]] to i8**
 // MSVC:   %[[vbtable:.*]] = load i8** %[[vbptr]]
 // MSVC:   %[[entry:.*]] = getelementptr inbounds i8* {{.*}}, i32 16
 // MSVC:   %[[entry_i32:.*]] = bitcast i8* %[[entry]] to i32*
 // MSVC:   %[[offset:.*]] = load i32* %[[entry_i32]]
-// MSVC:   add nsw i32 12, %[[offset]]
+// MSVC:   add nsw i32 4, %[[offset]]
 // MSVC: }
 
 // CHECK: attributes [[NUW]] = { nounwind{{.*}} }





More information about the cfe-commits mailing list