[cfe-commits] r66287 - in /cfe/trunk: lib/Sema/SemaAttr.cpp test/Sema/pragma-pack-2.c
Daniel Dunbar
daniel at zuster.org
Fri Mar 6 12:45:56 PST 2009
Author: ddunbar
Date: Fri Mar 6 14:45:54 2009
New Revision: 66287
URL: http://llvm.org/viewvc/llvm-project?rev=66287&view=rev
Log:
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)'
Modified:
cfe/trunk/lib/Sema/SemaAttr.cpp
cfe/trunk/test/Sema/pragma-pack-2.c
Modified: cfe/trunk/lib/Sema/SemaAttr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaAttr.cpp?rev=66287&r1=66286&r2=66287&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaAttr.cpp Fri Mar 6 14:45:54 2009
@@ -102,8 +102,11 @@
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 @@
if (PackContext == 0)
PackContext = new PragmaPackStack();
-
PragmaPackStack *Context = static_cast<PragmaPackStack*>(PackContext);
Modified: cfe/trunk/test/Sema/pragma-pack-2.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/pragma-pack-2.c?rev=66287&r1=66286&r2=66287&view=diff
==============================================================================
--- cfe/trunk/test/Sema/pragma-pack-2.c (original)
+++ cfe/trunk/test/Sema/pragma-pack-2.c Fri Mar 6 14:45:54 2009
@@ -64,3 +64,30 @@
#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];
More information about the cfe-commits
mailing list