diff options
author | Daniel Dunbar <daniel@zuster.org> | 2009-03-06 20:45:54 +0000 |
---|---|---|
committer | Daniel Dunbar <daniel@zuster.org> | 2009-03-06 20:45:54 +0000 |
commit | e03c6102cc85f9b338c3ba740bb36c4ea007db17 (patch) | |
tree | 6205e50c10c3836c8d1572819085f5def690c233 | |
parent | c2fd626cac7f3ec37e26f0a5dc74beb44bb83c6e (diff) | |
download | bcm5719-llvm-e03c6102cc85f9b338c3ba740bb36c4ea007db17.tar.gz bcm5719-llvm-e03c6102cc85f9b338c3ba740bb36c4ea007db17.zip |
Handle #pragma pack(0). I left this out of diagnostic because users should
really use pack() instead.
- <rdar://problem/6650243> clang warns about '#pragma pack(0)'
llvm-svn: 66287
-rw-r--r-- | clang/lib/Sema/SemaAttr.cpp | 6 | ||||
-rw-r--r-- | clang/test/Sema/pragma-pack-2.c | 27 |
2 files changed, 31 insertions, 2 deletions
diff --git a/clang/lib/Sema/SemaAttr.cpp b/clang/lib/Sema/SemaAttr.cpp index bf1e10e5b0b..37962ad1738 100644 --- a/clang/lib/Sema/SemaAttr.cpp +++ b/clang/lib/Sema/SemaAttr.cpp @@ -102,8 +102,11 @@ void Sema::ActOnPragmaPack(PragmaPackKind Kind, IdentifierInfo *Name, unsigned AlignmentVal = 0; if (Alignment) { llvm::APSInt Val; + + // pack(0) is like pack(), which just works out since that is what + // we use 0 for in PackAttr. if (!Alignment->isIntegerConstantExpr(Val, Context) || - !Val.isPowerOf2() || + !(Val == 0 || Val.isPowerOf2()) || Val.getZExtValue() > 16) { Diag(PragmaLoc, diag::warn_pragma_pack_invalid_alignment); Alignment->Destroy(Context); @@ -115,7 +118,6 @@ void Sema::ActOnPragmaPack(PragmaPackKind Kind, IdentifierInfo *Name, if (PackContext == 0) PackContext = new PragmaPackStack(); - PragmaPackStack *Context = static_cast<PragmaPackStack*>(PackContext); diff --git a/clang/test/Sema/pragma-pack-2.c b/clang/test/Sema/pragma-pack-2.c index e139be0be8f..c86136bf3e0 100644 --- a/clang/test/Sema/pragma-pack-2.c +++ b/clang/test/Sema/pragma-pack-2.c @@ -64,3 +64,30 @@ struct s2_4 { #pragma pack(pop) }; extern int a2_4[offsetof(struct s2_4, f1) == 4 ? 1 : -1]; + +#pragma pack(1) +struct s3_0 { + char f0; + int f1; +}; +#pragma pack() +struct s3_1 { + char f0; + int f1; +}; +extern int a3_0[offsetof(struct s3_0, f1) == 1 ? 1 : -1]; +extern int a3_1[offsetof(struct s3_1, f1) == 4 ? 1 : -1]; + +// pack(0) is like pack() +#pragma pack(1) +struct s4_0 { + char f0; + int f1; +}; +#pragma pack(0) +struct s4_1 { + char f0; + int f1; +}; +extern int a4_0[offsetof(struct s4_0, f1) == 1 ? 1 : -1]; +extern int a4_1[offsetof(struct s4_1, f1) == 4 ? 1 : -1]; |