The attribute in `struct foo { ... } __attribute__((packed));` is being
ignored when in C++ mode, but handled correctly in C mode. It was simply
being omitted in Sema::ActOnFinishCXXMemberSpecification, so I've added
it.

diff --git a/include/clang/Parse/Action.h b/include/clang/Parse/Action.h
index f211b5c..ecda087 100644
--- a/include/clang/Parse/Action.h
+++ b/include/clang/Parse/Action.h
@@ -1757,7 +1757,8 @@ public:
   virtual void ActOnFinishCXXMemberSpecification(Scope* S, SourceLocation RLoc,
                                                  DeclPtrTy TagDecl,
                                                  SourceLocation LBrac,
-                                                 SourceLocation RBrac) {
+                                                 SourceLocation RBrac,
+                                                 AttributeList *AttrList) {
   }
 
   //===---------------------------C++ Templates----------------------------===//
diff --git a/lib/Parse/ParseDeclCXX.cpp b/lib/Parse/ParseDeclCXX.cpp
index b92e753..e2f5e3c 100644
--- a/lib/Parse/ParseDeclCXX.cpp
+++ b/lib/Parse/ParseDeclCXX.cpp
@@ -1573,10 +1573,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,
diff --git a/lib/Sema/Sema.h b/lib/Sema/Sema.h
index c5b719b..29511ca 100644
--- a/lib/Sema/Sema.h
+++ b/lib/Sema/Sema.h
@@ -2498,7 +2498,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,
diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp
index db81e48..ded1aac 100644
--- a/lib/Sema/SemaDeclCXX.cpp
+++ b/lib/Sema/SemaDeclCXX.cpp
@@ -2166,7 +2166,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;
 
@@ -2174,7 +2175,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>()));
diff --git a/test/Sema/struct-packed-align.c b/test/Sema/struct-packed-align.c
index 60a9feb..2b94567 100644
--- a/test/Sema/struct-packed-align.c
+++ b/test/Sema/struct-packed-align.c
@@ -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 {
diff --git a/test/SemaCXX/class-layout.cpp b/test/SemaCXX/class-layout.cpp
index 2b8d1d3..f3c75f4 100644
--- a/test/SemaCXX/class-layout.cpp
+++ b/test/SemaCXX/class-layout.cpp
@@ -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 {
 
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to