diff options
author | Daniel Dunbar <daniel@zuster.org> | 2010-05-27 18:42:17 +0000 |
---|---|---|
committer | Daniel Dunbar <daniel@zuster.org> | 2010-05-27 18:42:17 +0000 |
commit | 6f739145b94ede1ca98b5a5e0e179c817c405d7b (patch) | |
tree | 20b15fe9effe41df1717cde0285dcaf622c12eb6 | |
parent | 638e7cf3a09436dce7f3150ff8e4f27d190bd2ed (diff) |
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!
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@104865 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/clang/Parse/Action.h | 1 | ||||
-rw-r--r-- | lib/Parse/ParsePragma.cpp | 2 | ||||
-rw-r--r-- | lib/Sema/SemaAttr.cpp | 7 | ||||
-rw-r--r-- | test/Sema/pragma-align-packed.c | 23 |
4 files changed, 33 insertions, 0 deletions
diff --git a/include/clang/Parse/Action.h b/include/clang/Parse/Action.h index d0968599c8..122fe850a1 100644 --- a/include/clang/Parse/Action.h +++ b/include/clang/Parse/Action.h @@ -2567,6 +2567,7 @@ public: 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 diff --git a/lib/Parse/ParsePragma.cpp b/lib/Parse/ParsePragma.cpp index 397d816c76..b27e655ff4 100644 --- a/lib/Parse/ParsePragma.cpp +++ b/lib/Parse/ParsePragma.cpp @@ -140,6 +140,8 @@ void PragmaOptionsHandler::HandlePragma(Preprocessor &PP, Token &OptionsTok) { 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")) diff --git a/lib/Sema/SemaAttr.cpp b/lib/Sema/SemaAttr.cpp index c540af2498..fcf5bfd669 100644 --- a/lib/Sema/SemaAttr.cpp +++ b/lib/Sema/SemaAttr.cpp @@ -146,6 +146,13 @@ void Sema::ActOnPragmaOptionsAlign(PragmaOptionsAlignKind Kind, 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()) { diff --git a/test/Sema/pragma-align-packed.c b/test/Sema/pragma-align-packed.c new file mode 100644 index 0000000000..6c9b06c6d6 --- /dev/null +++ b/test/Sema/pragma-align-packed.c @@ -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 |