[cfe-commits] r104865 - in /cfe/trunk: include/clang/Parse/Action.h lib/Parse/ParsePragma.cpp lib/Sema/SemaAttr.cpp test/Sema/pragma-align-packed.c
Daniel Dunbar
daniel at zuster.org
Thu May 27 11:42:17 PDT 2010
Author: ddunbar
Date: Thu May 27 13:42:17 2010
New Revision: 104865
URL: http://llvm.org/viewvc/llvm-project?rev=104865&view=rev
Log:
Parse/Sema: Add support for '#pragma options align=packed', which, it should be
noted, is not the same as __attribute__((packed)). That would be ridiculous!
Added:
cfe/trunk/test/Sema/pragma-align-packed.c
Modified:
cfe/trunk/include/clang/Parse/Action.h
cfe/trunk/lib/Parse/ParsePragma.cpp
cfe/trunk/lib/Sema/SemaAttr.cpp
Modified: cfe/trunk/include/clang/Parse/Action.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Action.h?rev=104865&r1=104864&r2=104865&view=diff
==============================================================================
--- cfe/trunk/include/clang/Parse/Action.h (original)
+++ cfe/trunk/include/clang/Parse/Action.h Thu May 27 13:42:17 2010
@@ -2567,6 +2567,7 @@
enum PragmaOptionsAlignKind {
POAK_Native, // #pragma options align=native
POAK_Natural, // #pragma options align=natural
+ POAK_Packed, // #pragma options align=packed
POAK_Power, // #pragma options align=power
POAK_Mac68k, // #pragma options align=mac68k
POAK_Reset // #pragma options align=reset
Modified: cfe/trunk/lib/Parse/ParsePragma.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParsePragma.cpp?rev=104865&r1=104864&r2=104865&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParsePragma.cpp (original)
+++ cfe/trunk/lib/Parse/ParsePragma.cpp Thu May 27 13:42:17 2010
@@ -140,6 +140,8 @@
Kind = Action::POAK_Native;
else if (II->isStr("natural"))
Kind = Action::POAK_Natural;
+ else if (II->isStr("packed"))
+ Kind = Action::POAK_Packed;
else if (II->isStr("power"))
Kind = Action::POAK_Power;
else if (II->isStr("mac68k"))
Modified: cfe/trunk/lib/Sema/SemaAttr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaAttr.cpp?rev=104865&r1=104864&r2=104865&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaAttr.cpp Thu May 27 13:42:17 2010
@@ -146,6 +146,13 @@
Context->setAlignment(0);
break;
+ // Note that '#pragma options align=packed' is not equivalent to attribute
+ // packed, it has a different precedence relative to attribute aligned.
+ case POAK_Packed:
+ Context->push(0);
+ Context->setAlignment(1);
+ break;
+
case POAK_Mac68k:
// Check if the target supports this.
if (!PP.getTargetInfo().hasAlignMac68kSupport()) {
Added: cfe/trunk/test/Sema/pragma-align-packed.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/pragma-align-packed.c?rev=104865&view=auto
==============================================================================
--- cfe/trunk/test/Sema/pragma-align-packed.c (added)
+++ cfe/trunk/test/Sema/pragma-align-packed.c Thu May 27 13:42:17 2010
@@ -0,0 +1,23 @@
+// RUN: %clang-cc1 -triple i386-apple-darwin9 -fsyntax-only -verify %s
+
+#pragma pack(push, 1)
+struct s0 {
+ char f0;
+ int f1 __attribute__((aligned(4)));
+};
+extern int a[sizeof(struct s0) == 5 ? 1 : -1];
+#pragma pack(pop)
+
+struct __attribute__((packed)) s1 {
+ char f0;
+ int f1 __attribute__((aligned(4)));
+};
+extern int a[sizeof(struct s1) == 8 ? 1 : -1];
+
+#pragma options align=packed
+struct s2 {
+ char f0;
+ int f1 __attribute__((aligned(4)));
+};
+extern int a[sizeof(struct s2) == 5 ? 1 : -1];
+#pragma options align=reset
More information about the cfe-commits
mailing list