]> granicus.if.org Git - clang/commitdiff
Don't add attributes for "#pragma pack" and friends to tag declarations which
authorEli Friedman <eli.friedman@gmail.com>
Wed, 8 Aug 2012 21:08:34 +0000 (21:08 +0000)
committerEli Friedman <eli.friedman@gmail.com>
Wed, 8 Aug 2012 21:08:34 +0000 (21:08 +0000)
are not definitions. This follows the behavior of both gcc and earlier
versions of clang. Regression from r156531.  <rdar://problem/12048621>.

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

lib/Sema/SemaDecl.cpp
lib/Sema/SemaTemplate.cpp
test/Sema/pragma-pack-6.c [new file with mode: 0644]

index 869fedb00c2aa9b9e260bd6fba28544c89ecb9a1..2b38718db9697cc075796f974133d94e434be2af 100644 (file)
@@ -8807,9 +8807,10 @@ CreateNewDecl:
     // many points during the parsing of a struct declaration (because
     // the #pragma tokens are effectively skipped over during the
     // parsing of the struct).
-    AddAlignmentAttributesForRecord(RD);
-    
-    AddMsStructLayoutForRecord(RD);
+    if (TUK == TUK_Definition) {
+      AddAlignmentAttributesForRecord(RD);
+      AddMsStructLayoutForRecord(RD);
+    }
   }
 
   if (ModulePrivateLoc.isValid()) {
index cbfa1ba42e07c470fad5a80481a6136fbe7ef317..c8e45016671d29a30f3334373eac616077867aac 100644 (file)
@@ -1064,8 +1064,10 @@ Sema::CheckClassTemplate(Scope *S, unsigned TagSpec, TagUseKind TUK,
 
   // Add alignment attributes if necessary; these attributes are checked when
   // the ASTContext lays out the structure.
-  AddAlignmentAttributesForRecord(NewClass);
-  AddMsStructLayoutForRecord(NewClass);
+  if (TUK == TUK_Definition) {
+    AddAlignmentAttributesForRecord(NewClass);
+    AddMsStructLayoutForRecord(NewClass);
+  }
 
   ClassTemplateDecl *NewTemplate
     = ClassTemplateDecl::Create(Context, SemanticContext, NameLoc,
diff --git a/test/Sema/pragma-pack-6.c b/test/Sema/pragma-pack-6.c
new file mode 100644 (file)
index 0000000..40659c2
--- /dev/null
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -triple i686-apple-darwin9 %s -fsyntax-only -verify
+
+// Pragma pack handling with tag declarations
+
+struct X;
+
+#pragma pack(2)
+struct X { int x; };
+struct Y;
+#pragma pack()
+
+struct Y { int y; };
+
+extern int check[__alignof(struct X) == 2 ? 1 : -1];
+extern int check[__alignof(struct Y) == 4 ? 1 : -1];
+