]> granicus.if.org Git - clang/commitdiff
Support __attribute__((packed)) (along with other attributes) at the
authorDouglas Gregor <dgregor@apple.com>
Mon, 29 Mar 2010 14:42:08 +0000 (14:42 +0000)
committerDouglas Gregor <dgregor@apple.com>
Mon, 29 Mar 2010 14:42:08 +0000 (14:42 +0000)
end of a struct/class/union in C++, from Justin Bogner!

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

include/clang/Parse/Action.h
lib/Parse/ParseDeclCXX.cpp
lib/Sema/Sema.h
lib/Sema/SemaDeclCXX.cpp
test/Sema/struct-packed-align.c
test/SemaCXX/class-layout.cpp

index b79e698d50c9689b120242fa22fc4a2a26787400..59cc0d218cec4bf481f0b2fd3bace57882e50573 100644 (file)
@@ -1761,7 +1761,8 @@ public:
   virtual void ActOnFinishCXXMemberSpecification(Scope* S, SourceLocation RLoc,
                                                  DeclPtrTy TagDecl,
                                                  SourceLocation LBrac,
-                                                 SourceLocation RBrac) {
+                                                 SourceLocation RBrac,
+                                                 AttributeList *AttrList) {
   }
 
   //===---------------------------C++ Templates----------------------------===//
index 9e232cbf325d2715fb7cc2de73bb1e4e93bc8a40..3dc6ad9b34a27a73f7ef5d7d35327a3a5effd26d 100644 (file)
@@ -1579,10 +1579,11 @@ void Parser::ParseCXXMemberSpecification(SourceLocation RecordLoc,
   // If attributes exist after class contents, parse them.
   llvm::OwningPtr<AttributeList> AttrList;
   if (Tok.is(tok::kw___attribute))
-    AttrList.reset(ParseGNUAttributes()); // FIXME: where should I put them?
+    AttrList.reset(ParseGNUAttributes());
 
   Actions.ActOnFinishCXXMemberSpecification(CurScope, RecordLoc, TagDecl,
-                                            LBraceLoc, RBraceLoc);
+                                            LBraceLoc, RBraceLoc,
+                                            AttrList.get());
 
   // C++ 9.2p2: Within the class member-specification, the class is regarded as
   // complete within function bodies, default arguments,
index d0a4f7cbf6c2c1671bfb39a798e7615a8e3cf374..9c661ba1b13658f1141190765f1e52b5ab745b93 100644 (file)
@@ -2502,7 +2502,8 @@ public:
   virtual void ActOnFinishCXXMemberSpecification(Scope* S, SourceLocation RLoc,
                                                  DeclPtrTy TagDecl,
                                                  SourceLocation LBrac,
-                                                 SourceLocation RBrac);
+                                                 SourceLocation RBrac,
+                                                 AttributeList *AttrList);
 
   virtual void ActOnReenterTemplateScope(Scope *S, DeclPtrTy Template);
   virtual void ActOnStartDelayedMemberDeclarations(Scope *S,
index b5dc73052282b6986b20a126df948c7e3e9149f0..ee16b9c4b14d27ce9544b9b8f69475ca1faf8d81 100644 (file)
@@ -2174,7 +2174,8 @@ void Sema::CheckCompletedCXXClass(CXXRecordDecl *Record) {
 void Sema::ActOnFinishCXXMemberSpecification(Scope* S, SourceLocation RLoc,
                                              DeclPtrTy TagDecl,
                                              SourceLocation LBrac,
-                                             SourceLocation RBrac) {
+                                             SourceLocation RBrac,
+                                             AttributeList *AttrList) {
   if (!TagDecl)
     return;
 
@@ -2182,7 +2183,7 @@ void Sema::ActOnFinishCXXMemberSpecification(Scope* S, SourceLocation RLoc,
 
   ActOnFields(S, RLoc, TagDecl,
               (DeclPtrTy*)FieldCollector->getCurFields(),
-              FieldCollector->getCurNumFields(), LBrac, RBrac, 0);
+              FieldCollector->getCurNumFields(), LBrac, RBrac, AttrList);
 
   CheckCompletedCXXClass(
                       dyn_cast_or_null<CXXRecordDecl>(TagDecl.getAs<Decl>()));
index 60a9febafbad1eac4af4167657708c10424340f9..2b9456703c7274a4e7a527fed191bd87e782edb3 100644 (file)
@@ -37,6 +37,14 @@ struct __attribute__((packed)) packed_fas {
 extern int d1[sizeof(struct packed_fas) == 1 ? 1 : -1];
 extern int d2[__alignof(struct packed_fas) == 1 ? 1 : -1];
 
+struct packed_after_fas {
+    char a;
+    int b[];
+} __attribute__((packed));
+
+extern int d1_2[sizeof(struct packed_after_fas) == 1 ? 1 : -1];
+extern int d2_2[__alignof(struct packed_after_fas) == 1 ? 1 : -1];
+
 // Alignment
 
 struct __attribute__((aligned(8))) as1 {
index 2b8d1d3210b349ece750bf34bdbf171f50ca8a2c..f3c75f4b27d3553d797016d3c275ec9e111a56e7 100644 (file)
@@ -48,6 +48,13 @@ struct H : G { };
 
 SA(6, sizeof(H) == 1);
 
+struct I {
+  char b;
+  int a;
+} __attribute__((packed));
+
+SA(6_1, sizeof(I) == 5);
+
 // PR5580
 namespace PR5580 {