[llvm-branch-commits] [cfe-branch] r121564 - in /cfe/branches/Apple/whitney: lib/AST/RecordLayoutBuilder.cpp test/SemaCXX/pragma-pack.cpp
Daniel Dunbar
daniel at zuster.org
Fri Dec 10 13:38:18 PST 2010
Author: ddunbar
Date: Fri Dec 10 15:38:18 2010
New Revision: 121564
URL: http://llvm.org/viewvc/llvm-project?rev=121564&view=rev
Log:
Merge r121335:
--
Author: Argyrios Kyrtzidis <akyrtzi at gmail.com>
Date: Thu Dec 9 00:35:20 2010 +0000
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/branches/Apple/whitney/test/SemaCXX/pragma-pack.cpp
Modified:
cfe/branches/Apple/whitney/lib/AST/RecordLayoutBuilder.cpp
Modified: cfe/branches/Apple/whitney/lib/AST/RecordLayoutBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/whitney/lib/AST/RecordLayoutBuilder.cpp?rev=121564&r1=121563&r2=121564&view=diff
==============================================================================
--- cfe/branches/Apple/whitney/lib/AST/RecordLayoutBuilder.cpp (original)
+++ cfe/branches/Apple/whitney/lib/AST/RecordLayoutBuilder.cpp Fri Dec 10 15:38:18 2010
@@ -1108,7 +1108,14 @@
return 0;
}
- 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);
@@ -1126,7 +1133,7 @@
Size = std::max(Size, Offset + Layout.getSize());
// Remember max struct/class alignment.
- UpdateAlignment(BaseAlign);
+ UpdateAlignment(BaseAlign, UnpackedBaseAlign);
return Offset;
}
Added: cfe/branches/Apple/whitney/test/SemaCXX/pragma-pack.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/whitney/test/SemaCXX/pragma-pack.cpp?rev=121564&view=auto
==============================================================================
--- cfe/branches/Apple/whitney/test/SemaCXX/pragma-pack.cpp (added)
+++ cfe/branches/Apple/whitney/test/SemaCXX/pragma-pack.cpp Fri Dec 10 15:38:18 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 llvm-branch-commits
mailing list