]> granicus.if.org Git - clang/commitdiff
Handle #pragma pack(0). I left this out of diagnostic because users should
authorDaniel Dunbar <daniel@zuster.org>
Fri, 6 Mar 2009 20:45:54 +0000 (20:45 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Fri, 6 Mar 2009 20:45:54 +0000 (20:45 +0000)
really use pack() instead.
 - <rdar://problem/6650243> clang warns about '#pragma pack(0)'

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@66287 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaAttr.cpp
test/Sema/pragma-pack-2.c

index bf1e10e5b0be707b062f743711b2d5b8aac9da73..37962ad173849242a1261e175bd6055567ec7c26 100644 (file)
@@ -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);
   
index e139be0be8fb847736050ff1941e31121e2f05fc..c86136bf3e0f992c14989f7322d098f462eb787d 100644 (file)
@@ -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];