r199132 - [ms-abi] Leading VFPtrs don't suppress the leading zero sized flag

Warren Hunt whunt at google.com
Mon Jan 13 11:55:52 PST 2014


Author: whunt
Date: Mon Jan 13 13:55:52 2014
New Revision: 199132

URL: http://llvm.org/viewvc/llvm-project?rev=199132&view=rev
Log:
[ms-abi] Leading VFPtrs don't suppress the leading zero sized flag

The MS-ABI tracks a bit that asserts that the first sub-object is zero 
sized.  This bit is used to add padding between objects if there's the 
potential for zero sized objects to alias.  The bit is still true even 
if the zero sized base is lead by a VFPtr.  This patch makes clang mimic 
that behavior.


Modified:
    cfe/trunk/lib/AST/RecordLayoutBuilder.cpp
    cfe/trunk/test/Layout/ms-x86-alias-avoidance-padding.cpp

Modified: cfe/trunk/lib/AST/RecordLayoutBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/RecordLayoutBuilder.cpp?rev=199132&r1=199131&r2=199132&view=diff
==============================================================================
--- cfe/trunk/lib/AST/RecordLayoutBuilder.cpp (original)
+++ cfe/trunk/lib/AST/RecordLayoutBuilder.cpp Mon Jan 13 13:55:52 2014
@@ -2302,8 +2302,10 @@ MicrosoftRecordLayoutBuilder::layoutNonV
     if (!BaseLayout.hasExtendableVFPtr())
       continue;
     // If we don't have a primary base, this one qualifies.
-    if (!PrimaryBase)
+    if (!PrimaryBase) {
       PrimaryBase = BaseDecl;
+      LeadsWithZeroSizedBase = BaseLayout.leadsWithZeroSizedBase();
+    }
     // Lay out the base.
     layoutNonVirtualBase(BaseDecl, BaseLayout, PreviousBaseLayout);
   }

Modified: cfe/trunk/test/Layout/ms-x86-alias-avoidance-padding.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Layout/ms-x86-alias-avoidance-padding.cpp?rev=199132&r1=199131&r2=199132&view=diff
==============================================================================
--- cfe/trunk/test/Layout/ms-x86-alias-avoidance-padding.cpp (original)
+++ cfe/trunk/test/Layout/ms-x86-alias-avoidance-padding.cpp Mon Jan 13 13:55:52 2014
@@ -255,10 +255,54 @@ struct F : virtual D, virtual B {};
 // CHECK-X64-NEXT:      | [sizeof=32, align=8
 // CHECK-X64-NEXT:      |  nvsize=8, nvalign=8]
 
+struct JC0 {
+	JC0() { printf("JC0 : %d\n", (int)((char*)this - buffer)); }
+};
+struct JC1 : JC0 {
+	virtual void f() {}
+	JC1() { printf("JC1 : %d\n", (int)((char*)this - buffer)); }
+};
+struct JC2 : JC1 {
+	JC2() { printf("JC2 : %d\n", (int)((char*)this - buffer)); }
+};
+struct JC4 : JC1, JC2 {
+	JC4() { printf("JC4 : %d\n", (int)((char*)this - buffer)); }
+};
+
+// CHECK: *** Dumping AST Record Layout
+// CHECK: *** Dumping AST Record Layout
+// CHECK: *** Dumping AST Record Layout
+// CHECK: *** Dumping AST Record Layout
+// CHECK-NEXT:    0 | struct JC4
+// CHECK-NEXT:    0 |   struct JC1 (primary base)
+// CHECK-NEXT:    0 |     (JC1 vftable pointer)
+// CHECK-NEXT:    4 |     struct JC0 (base) (empty)
+// CHECK-NEXT:    8 |   struct JC2 (base)
+// CHECK-NEXT:    8 |     struct JC1 (primary base)
+// CHECK-NEXT:    8 |       (JC1 vftable pointer)
+// CHECK-NEXT:   12 |       struct JC0 (base) (empty)
+// CHECK-NEXT:      | [sizeof=12, align=4
+// CHECK-NEXT:      |  nvsize=12, nvalign=4]
+// CHECK-x64: *** Dumping AST Record Layout
+// CHECK-x64: *** Dumping AST Record Layout
+// CHECK-x64: *** Dumping AST Record Layout
+// CHECK-x64: *** Dumping AST Record Layout
+// CHECK-x64-NEXT:    0 | struct JC4
+// CHECK-x64-NEXT:    0 |   struct JC1 (primary base)
+// CHECK-x64-NEXT:    0 |     (JC1 vftable pointer)
+// CHECK-x64-NEXT:    8 |     struct JC0 (base) (empty)
+// CHECK-x64-NEXT:   16 |   struct JC2 (base)
+// CHECK-x64-NEXT:   16 |     struct JC1 (primary base)
+// CHECK-x64-NEXT:   16 |       (JC1 vftable pointer)
+// CHECK-x64-NEXT:   24 |       struct JC0 (base) (empty)
+// CHECK-x64-NEXT:      | [sizeof=24, align=8
+// CHECK-x64-NEXT:      |  nvsize=24, nvalign=8]
+
 int a[
 sizeof(AT3) +
 sizeof(BT3) +
 sizeof(T3) +
 sizeof(E) +
 sizeof(F) +
+sizeof(JC4) +
 0];





More information about the cfe-commits mailing list