diff options
-rw-r--r-- | lib/AST/ASTContext.cpp | 3 | ||||
-rw-r--r-- | test/SemaCXX/empty-class-layout.cpp | 15 |
2 files changed, 17 insertions, 1 deletions
diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp index a1faaa00ec..44f13b6906 100644 --- a/lib/AST/ASTContext.cpp +++ b/lib/AST/ASTContext.cpp @@ -3994,7 +3994,8 @@ ASTContext::getConstantArrayElementCount(const ConstantArrayType *CA) const { uint64_t ElementCount = 1; do { ElementCount *= CA->getSize().getZExtValue(); - CA = dyn_cast<ConstantArrayType>(CA->getElementType()); + CA = dyn_cast_or_null<ConstantArrayType>( + CA->getElementType()->getAsArrayTypeUnsafe()); } while (CA); return ElementCount; } diff --git a/test/SemaCXX/empty-class-layout.cpp b/test/SemaCXX/empty-class-layout.cpp index 951f16c1b0..3cfc491ef6 100644 --- a/test/SemaCXX/empty-class-layout.cpp +++ b/test/SemaCXX/empty-class-layout.cpp @@ -156,3 +156,18 @@ namespace Test7 { }; SA(0, sizeof(Test) == 2); } + +namespace Test8 { + // Test that type sugar doesn't make us incorrectly determine the size of an + // array of empty classes. + struct Empty1 {}; + struct Empty2 {}; + struct Empties : Empty1, Empty2 {}; + typedef Empty1 Sugar[4]; + struct A : Empty2, Empties { + // This must go at offset 2, because if it were at offset 0, + // V[0][1] would overlap Empties::Empty1. + Sugar V[1]; + }; + SA(0, sizeof(A) == 6); +} |