[cfe-commits] r131142 - in /cfe/trunk: lib/AST/RecordLayoutBuilder.cpp test/CodeGen/ms_struct-pack.c
Fariborz Jahanian
fjahanian at apple.com
Tue May 10 12:00:50 PDT 2011
Author: fjahanian
Date: Tue May 10 14:00:50 2011
New Revision: 131142
URL: http://llvm.org/viewvc/llvm-project?rev=131142&view=rev
Log:
Support pack pragma and ms_struct attributes. // rdar://8823265
Added:
cfe/trunk/test/CodeGen/ms_struct-pack.c
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=131142&r1=131141&r2=131142&view=diff
==============================================================================
--- cfe/trunk/lib/AST/RecordLayoutBuilder.cpp (original)
+++ cfe/trunk/lib/AST/RecordLayoutBuilder.cpp Tue May 10 14:00:50 2011
@@ -1299,6 +1299,13 @@
uint64_t UnpaddedFieldOffset =
getDataSizeInBits() - UnfilledBitsInLastByte;
FieldAlign = std::max(FieldAlign, FieldAlignLastFD);
+ // The maximum field alignment overrides the aligned attribute.
+ if (!MaxFieldAlignment.isZero()) {
+ unsigned MaxFieldAlignmentInBits =
+ Context.toBits(MaxFieldAlignment);
+ FieldAlign = std::min(FieldAlign, MaxFieldAlignmentInBits);
+ }
+
uint64_t NewSizeInBits =
llvm::RoundUpToAlignment(UnpaddedFieldOffset, FieldAlign);
setDataSize(llvm::RoundUpToAlignment(NewSizeInBits,
Added: cfe/trunk/test/CodeGen/ms_struct-pack.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/ms_struct-pack.c?rev=131142&view=auto
==============================================================================
--- cfe/trunk/test/CodeGen/ms_struct-pack.c (added)
+++ cfe/trunk/test/CodeGen/ms_struct-pack.c Tue May 10 14:00:50 2011
@@ -0,0 +1,34 @@
+// RUN: %clang_cc1 -emit-llvm-only -triple i386-apple-darwin9 %s
+// rdar://8823265
+
+#pragma pack(1)
+struct _two_ms {
+ short m:9; // size is 2
+ int q:27; // size is 6
+ short w:13; // size is 8
+ short e:3; // size is 8
+ char r:4; // size is 9
+ char t:7; // size is 10
+ short y:16; // size is 12
+// clang and gcc start differing here. clang seems to follow the rules.
+ short u:1; // size is clang: 13 gcc:14
+ char i:2; // size is 14
+ int a; // size is 18
+ char o:6; // size is 19
+ char s:2; // size is 19
+ short d:10; // size is 21
+ short f:4; // size is 21
+ char b; // size is 22
+ char g:1; // size is 23
+ short h:13; // size is 25
+ char j:8; // size is 26
+ char k:5; // size is 27
+ char c; // size is 28
+ int l:28; // size is 32
+ char z:7; // size is 33
+ int x:20; // size is clang: 36 gcc:38
+ } __attribute__((__ms_struct__));
+typedef struct _two_ms two_ms;
+
+// gcc says size is 38, but its does not seem right!
+static int a1[(sizeof(two_ms) == 36) - 1];
More information about the cfe-commits
mailing list