[cfe-commits] r104464 - in /cfe/trunk: lib/AST/RecordLayoutBuilder.cpp test/SemaCXX/empty-class-layout.cpp
Anders Carlsson
andersca at mac.com
Sun May 23 11:14:24 PDT 2010
Author: andersca
Date: Sun May 23 13:14:24 2010
New Revision: 104464
URL: http://llvm.org/viewvc/llvm-project?rev=104464&view=rev
Log:
When recording empty subobjects we should always look at the primary virtual base.
Modified:
cfe/trunk/lib/AST/RecordLayoutBuilder.cpp
cfe/trunk/test/SemaCXX/empty-class-layout.cpp
Modified: cfe/trunk/lib/AST/RecordLayoutBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/RecordLayoutBuilder.cpp?rev=104464&r1=104463&r2=104464&view=diff
==============================================================================
--- cfe/trunk/lib/AST/RecordLayoutBuilder.cpp (original)
+++ cfe/trunk/lib/AST/RecordLayoutBuilder.cpp Sun May 23 13:14:24 2010
@@ -530,8 +530,15 @@
UpdateEmptyClassOffsets(FD, Offset + FieldOffset);
}
+ const CXXRecordDecl *PrimaryBase = Layout.getPrimaryBase();
+
if (UpdateVBases) {
// FIXME: Update virtual bases.
+ } else if (PrimaryBase && Layout.getPrimaryBaseWasVirtual()) {
+ // We always want to update the offsets of a primary virtual base.
+ assert(Layout.getVBaseClassOffset(PrimaryBase) == 0 &&
+ "primary base class offset must always be 0!");
+ UpdateEmptyClassOffsets(PrimaryBase, Offset, /*UpdateVBases=*/false);
}
}
Modified: cfe/trunk/test/SemaCXX/empty-class-layout.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/empty-class-layout.cpp?rev=104464&r1=104463&r2=104464&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/empty-class-layout.cpp (original)
+++ cfe/trunk/test/SemaCXX/empty-class-layout.cpp Sun May 23 13:14:24 2010
@@ -2,6 +2,8 @@
#define SA(n, p) int a##n[(p) ? 1 : -1]
+namespace Test0 {
+
struct A { int a; };
SA(0, sizeof(A) == 4);
@@ -66,3 +68,19 @@
struct S8 : Empty, A {
};
SA(12, sizeof(S8) == 4);
+
+}
+
+namespace Test1 {
+
+// Test that we don't try to place both A subobjects at offset 0.
+struct A { };
+class B { virtual void f(); };
+class C : A, virtual B { };
+struct D : virtual C { };
+struct E : virtual A { };
+class F : D, E { };
+
+SA(0, sizeof(F) == 24);
+
+}
More information about the cfe-commits
mailing list