From 260995b86b8895ac22da92415cea9690c6905291 Mon Sep 17 00:00:00 2001 From: Aaron Ballman Date: Wed, 15 Oct 2014 16:58:18 +0000 Subject: [PATCH] Adding attributes to the IndirectFieldDecl that we generate for anonymous struct/union fields. This fixes PR20930. llvm-svn: 219807 --- clang/lib/AST/ASTImporter.cpp | 9 ++++++--- clang/lib/Sema/SemaDecl.cpp | 10 ++++++---- clang/lib/Sema/SemaTemplateInstantiateDecl.cpp | 9 +++++---- clang/test/Misc/ast-dump-attr.cpp | 17 ++++++++++++++++- clang/test/Sema/anonymous-struct-union.c | 10 ++++++++++ 5 files changed, 43 insertions(+), 12 deletions(-) diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp index ca7ab63..1627e47 100644 --- a/clang/lib/AST/ASTImporter.cpp +++ b/clang/lib/AST/ASTImporter.cpp @@ -2958,9 +2958,12 @@ Decl *ASTNodeImporter::VisitIndirectFieldDecl(IndirectFieldDecl *D) { } 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); diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 22a7e73..65eafd5 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -3723,10 +3723,12 @@ static bool InjectAnonymousStructOrUnionMembers(Sema &SemaRef, Scope *S, 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(); diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp index 274105d..ec8c08d 100644 --- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp +++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp @@ -653,11 +653,12 @@ Decl *TemplateDeclInstantiator::VisitIndirectFieldDecl(IndirectFieldDecl *D) { } QualType T = cast(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()); diff --git a/clang/test/Misc/ast-dump-attr.cpp b/clang/test/Misc/ast-dump-attr.cpp index 1aa6adf..446f0fa 100644 --- a/clang/test/Misc/ast-dump-attr.cpp +++ b/clang/test/Misc/ast-dump-attr.cpp @@ -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 +} +} diff --git a/clang/test/Sema/anonymous-struct-union.c b/clang/test/Sema/anonymous-struct-union.c index 26dbeb8..652383e 100644 --- a/clang/test/Sema/anonymous-struct-union.c +++ b/clang/test/Sema/anonymous-struct-union.c @@ -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}} +} -- 2.7.4