r219807 - Adding attributes to the IndirectFieldDecl that we generate for anonymous struct/union fields. This fixes PR20930.

Aaron Ballman aaron at aaronballman.com
Wed Oct 15 09:58:19 PDT 2014


Author: aaronballman
Date: Wed Oct 15 11:58:18 2014
New Revision: 219807

URL: http://llvm.org/viewvc/llvm-project?rev=219807&view=rev
Log:
Adding attributes to the IndirectFieldDecl that we generate for anonymous struct/union fields. This fixes PR20930.

Modified:
    cfe/trunk/lib/AST/ASTImporter.cpp
    cfe/trunk/lib/Sema/SemaDecl.cpp
    cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
    cfe/trunk/test/Misc/ast-dump-attr.cpp
    cfe/trunk/test/Sema/anonymous-struct-union.c

Modified: cfe/trunk/lib/AST/ASTImporter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTImporter.cpp?rev=219807&r1=219806&r2=219807&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ASTImporter.cpp (original)
+++ cfe/trunk/lib/AST/ASTImporter.cpp Wed Oct 15 11:58:18 2014
@@ -2958,9 +2958,12 @@ Decl *ASTNodeImporter::VisitIndirectFiel
   }
 
   IndirectFieldDecl *ToIndirectField = IndirectFieldDecl::Create(
-                                         Importer.getToContext(), DC,
-                                         Loc, Name.getAsIdentifierInfo(), T,
-                                         NamedChain, D->getChainingSize());
+      Importer.getToContext(), DC, Loc, Name.getAsIdentifierInfo(), T,
+      NamedChain, D->getChainingSize());
+
+  for (const auto *Attr : D->attrs())
+    ToIndirectField->addAttr(Attr->clone(Importer.getToContext()));
+
   ToIndirectField->setAccess(D->getAccess());
   ToIndirectField->setLexicalDeclContext(LexicalDC);
   Importer.Imported(D, ToIndirectField);

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=219807&r1=219806&r2=219807&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Wed Oct 15 11:58:18 2014
@@ -3723,10 +3723,12 @@ static bool InjectAnonymousStructOrUnion
         for (unsigned i = 0; i < Chaining.size(); i++)
           NamedChain[i] = Chaining[i];
 
-        IndirectFieldDecl* IndirectField =
-          IndirectFieldDecl::Create(SemaRef.Context, Owner, VD->getLocation(),
-                                    VD->getIdentifier(), VD->getType(),
-                                    NamedChain, Chaining.size());
+        IndirectFieldDecl *IndirectField = IndirectFieldDecl::Create(
+            SemaRef.Context, Owner, VD->getLocation(), VD->getIdentifier(),
+            VD->getType(), NamedChain, Chaining.size());
+
+        for (const auto *Attr : VD->attrs())
+          IndirectField->addAttr(Attr->clone(SemaRef.Context));
 
         IndirectField->setAccess(AS);
         IndirectField->setImplicit();

Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp?rev=219807&r1=219806&r2=219807&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp Wed Oct 15 11:58:18 2014
@@ -653,11 +653,12 @@ Decl *TemplateDeclInstantiator::VisitInd
   }
 
   QualType T = cast<FieldDecl>(NamedChain[i-1])->getType();
-  IndirectFieldDecl* IndirectField
-    = IndirectFieldDecl::Create(SemaRef.Context, Owner, D->getLocation(),
-                                D->getIdentifier(), T,
-                                NamedChain, D->getChainingSize());
+  IndirectFieldDecl *IndirectField = IndirectFieldDecl::Create(
+      SemaRef.Context, Owner, D->getLocation(), D->getIdentifier(), T,
+      NamedChain, D->getChainingSize());
 
+  for (const auto *Attr : D->attrs())
+    IndirectField->addAttr(Attr->clone(SemaRef.Context));
 
   IndirectField->setImplicit(D->isImplicit());
   IndirectField->setAccess(D->getAccess());

Modified: cfe/trunk/test/Misc/ast-dump-attr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Misc/ast-dump-attr.cpp?rev=219807&r1=219806&r2=219807&view=diff
==============================================================================
--- cfe/trunk/test/Misc/ast-dump-attr.cpp (original)
+++ cfe/trunk/test/Misc/ast-dump-attr.cpp Wed Oct 15 11:58:18 2014
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -triple x86_64-pc-linux -std=c++11 -ast-dump -ast-dump-filter Test %s | FileCheck --strict-whitespace %s
+// RUN: %clang_cc1 -triple x86_64-pc-linux -std=c++11 -Wno-deprecated-declarations -ast-dump -ast-dump-filter Test %s | FileCheck --strict-whitespace %s
 
 int TestLocation
 __attribute__((unused));
@@ -135,3 +135,18 @@ void func() {
   // CHECK-NOT: NoReturnAttr
   // CHECK: CXXConversionDecl{{.*}}operator void (*)() __attribute__((noreturn))
 }
+
+namespace PR20930 {
+struct S {
+  struct { int Test __attribute__((deprecated)); };
+  // CHECK: FieldDecl{{.*}}Test 'int'
+  // CHECK-NEXT: DeprecatedAttr
+};
+
+void f() {
+  S s;
+  s.Test = 1;
+  // CHECK: IndirectFieldDecl{{.*}}Test 'int'
+  // CHECK: DeprecatedAttr
+}
+}

Modified: cfe/trunk/test/Sema/anonymous-struct-union.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/anonymous-struct-union.c?rev=219807&r1=219806&r2=219807&view=diff
==============================================================================
--- cfe/trunk/test/Sema/anonymous-struct-union.c (original)
+++ cfe/trunk/test/Sema/anonymous-struct-union.c Wed Oct 15 11:58:18 2014
@@ -108,3 +108,13 @@ struct s {
   struct { int i; };
   int a[];
 };
+
+// PR20930
+struct s3 {
+  struct { int A __attribute__((deprecated)); }; // expected-note {{'A' has been explicitly marked deprecated here}}
+};
+
+void deprecated_anonymous_struct_member(void) {
+  struct s3 s;
+  s.A = 1; // expected-warning {{'A' is deprecated}}
+}





More information about the cfe-commits mailing list