[cfe-commits] r121352 - in /cfe/trunk: lib/AST/RecordLayoutBuilder.cpp test/SemaCXX/pragma-pack.cpp
Argyrios Kyrtzidis
akyrtzi at gmail.com
Wed Dec 8 18:47:58 PST 2010
Author: akirtzidis
Date: Wed Dec 8 20:47:58 2010
New Revision: 121352
URL: http://llvm.org/viewvc/llvm-project?rev=121352&view=rev
Log:
Fix another unnecessary-struct-padding issue.
Modified:
cfe/trunk/lib/AST/RecordLayoutBuilder.cpp
cfe/trunk/test/SemaCXX/pragma-pack.cpp
Modified: cfe/trunk/lib/AST/RecordLayoutBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/RecordLayoutBuilder.cpp?rev=121352&r1=121351&r2=121352&view=diff
==============================================================================
--- cfe/trunk/lib/AST/RecordLayoutBuilder.cpp (original)
+++ cfe/trunk/lib/AST/RecordLayoutBuilder.cpp Wed Dec 8 20:47:58 2010
@@ -807,8 +807,17 @@
Size += GetVirtualPointersSize(RD);
DataSize = Size;
+ unsigned UnpackedBaseAlign = Context.Target.getPointerAlign(0);
+ unsigned BaseAlign = (Packed) ? 8 : UnpackedBaseAlign;
+
+ // The maximum field alignment overrides base align.
+ if (MaxFieldAlignment) {
+ BaseAlign = std::min(BaseAlign, MaxFieldAlignment);
+ UnpackedBaseAlign = std::min(UnpackedBaseAlign, MaxFieldAlignment);
+ }
+
// Update the alignment.
- UpdateAlignment(Context.Target.getPointerAlign(0));
+ UpdateAlignment(BaseAlign, UnpackedBaseAlign);
}
BaseSubobjectInfo *
Modified: cfe/trunk/test/SemaCXX/pragma-pack.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/pragma-pack.cpp?rev=121352&r1=121351&r2=121352&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/pragma-pack.cpp (original)
+++ cfe/trunk/test/SemaCXX/pragma-pack.cpp Wed Dec 8 20:47:58 2010
@@ -6,11 +6,29 @@
int i;
};
-#pragma pack(1)
+#pragma pack(push, 1)
struct Sub : public Base {
char c;
};
+#pragma pack(pop)
int check[sizeof(Sub) == 5 ? 1 : -1];
}
+
+namespace check2 {
+
+struct Base {
+ virtual ~Base();
+ int x;
+};
+
+#pragma pack(push, 1)
+struct Sub : virtual Base {
+ char c;
+};
+#pragma pack(pop)
+
+int check[sizeof(Sub) == 13 ? 1 : -1];
+
+}
More information about the cfe-commits
mailing list