[cfe-commits] r121335 - in /cfe/trunk: lib/AST/RecordLayoutBuilder.cpp test/SemaCXX/pragma-pack.cpp
Argyrios Kyrtzidis
akyrtzi at gmail.com
Wed Dec 8 16:35:21 PST 2010
Author: akirtzidis
Date: Wed Dec 8 18:35:20 2010
New Revision: 121335
URL: http://llvm.org/viewvc/llvm-project?rev=121335&view=rev
Log:
Before determining the effect the alignment of base struct will have in the aligment of the sub-struct,
take into account if the sub-struct is packed and its maximum field alignment.
Fixes rdar://8745206
Added:
cfe/trunk/test/SemaCXX/pragma-pack.cpp
Modified:
cfe/trunk/lib/AST/RecordLayoutBuilder.cpp
Modified: cfe/trunk/lib/AST/RecordLayoutBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/RecordLayoutBuilder.cpp?rev=121335&r1=121334&r2=121335&view=diff
==============================================================================
--- cfe/trunk/lib/AST/RecordLayoutBuilder.cpp (original)
+++ cfe/trunk/lib/AST/RecordLayoutBuilder.cpp Wed Dec 8 18:35:20 2010
@@ -1092,7 +1092,14 @@
return CharUnits::Zero();
}
- unsigned BaseAlign = Layout.getNonVirtualAlign();
+ unsigned UnpackedBaseAlign = Layout.getNonVirtualAlign();
+ unsigned BaseAlign = (Packed) ? 8 : UnpackedBaseAlign;
+
+ // The maximum field alignment overrides base align.
+ if (MaxFieldAlignment) {
+ BaseAlign = std::min(BaseAlign, MaxFieldAlignment);
+ UnpackedBaseAlign = std::min(UnpackedBaseAlign, MaxFieldAlignment);
+ }
// Round up the current record size to the base's alignment boundary.
uint64_t Offset = llvm::RoundUpToAlignment(DataSize, BaseAlign);
@@ -1110,7 +1117,7 @@
Size = std::max(Size, Offset + Layout.getSize());
// Remember max struct/class alignment.
- UpdateAlignment(BaseAlign);
+ UpdateAlignment(BaseAlign, UnpackedBaseAlign);
return toCharUnits(Offset);
}
Added: cfe/trunk/test/SemaCXX/pragma-pack.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/pragma-pack.cpp?rev=121335&view=auto
==============================================================================
--- cfe/trunk/test/SemaCXX/pragma-pack.cpp (added)
+++ cfe/trunk/test/SemaCXX/pragma-pack.cpp Wed Dec 8 18:35:20 2010
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -triple i686-apple-darwin9 -fsyntax-only -verify %s
+
+namespace rdar8745206 {
+
+struct Base {
+ int i;
+};
+
+#pragma pack(1)
+struct Sub : public Base {
+ char c;
+};
+
+int check[sizeof(Sub) == 5 ? 1 : -1];
+
+}
More information about the cfe-commits
mailing list