From 485081104cd7d2700ae0c18dd0887cd6251bcfd3 Mon Sep 17 00:00:00 2001 From: Akira Hatanaka Date: Tue, 19 Jun 2018 05:04:44 +0000 Subject: [PATCH] [Sema] Produce diagnostics for attribute 'trivial_abi' that appears after the closing brace of a class declaration. Merge the two call sites of checkIllFormedTrivialABIStruct and sink it into CheckCompletedCXXClass so that it is called after the attribute has been attached to the CXXRecordDecl. rdar://problem/40873297 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@335021 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaDeclCXX.cpp | 11 +++++------ lib/Sema/SemaTemplateInstantiate.cpp | 4 ---- test/SemaObjCXX/attr-trivial-abi.mm | 4 ++++ 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp index e21f380fb7..7a7e0378cf 100644 --- a/lib/Sema/SemaDeclCXX.cpp +++ b/lib/Sema/SemaDeclCXX.cpp @@ -6018,6 +6018,10 @@ void Sema::CheckCompletedCXXClass(CXXRecordDecl *Record) { } } + // See if trivial_abi has to be dropped. + if (Record->hasAttr()) + checkIllFormedTrivialABIStruct(*Record); + // Set HasTrivialSpecialMemberForCall if the record has attribute // "trivial_abi". bool HasTrivialABI = Record->hasAttr(); @@ -7810,17 +7814,12 @@ void Sema::ActOnFinishCXXMemberSpecification(Scope* S, SourceLocation RLoc, l->getName(); } - // See if trivial_abi has to be dropped. - auto *RD = dyn_cast(TagDecl); - if (RD && RD->hasAttr()) - checkIllFormedTrivialABIStruct(*RD); - ActOnFields(S, RLoc, TagDecl, llvm::makeArrayRef( // strict aliasing violation! reinterpret_cast(FieldCollector->getCurFields()), FieldCollector->getCurNumFields()), LBrac, RBrac, AttrList); - CheckCompletedCXXClass(RD); + CheckCompletedCXXClass(dyn_cast_or_null(TagDecl)); } /// AddImplicitlyDeclaredMembersToClass - Adds any implicitly-declared diff --git a/lib/Sema/SemaTemplateInstantiate.cpp b/lib/Sema/SemaTemplateInstantiate.cpp index ebda251c64..2218bdd958 100644 --- a/lib/Sema/SemaTemplateInstantiate.cpp +++ b/lib/Sema/SemaTemplateInstantiate.cpp @@ -2123,10 +2123,6 @@ Sema::InstantiateClass(SourceLocation PointOfInstantiation, } } - // See if trivial_abi has to be dropped. - if (Instantiation && Instantiation->hasAttr()) - checkIllFormedTrivialABIStruct(*Instantiation); - // Finish checking fields. ActOnFields(nullptr, Instantiation->getLocation(), Instantiation, Fields, SourceLocation(), SourceLocation(), nullptr); diff --git a/test/SemaObjCXX/attr-trivial-abi.mm b/test/SemaObjCXX/attr-trivial-abi.mm index c83a94dcd9..fe8baee473 100644 --- a/test/SemaObjCXX/attr-trivial-abi.mm +++ b/test/SemaObjCXX/attr-trivial-abi.mm @@ -18,6 +18,10 @@ struct __attribute__((trivial_abi)) S3 { // expected-warning {{'trivial_abi' can virtual void m(); }; +struct S3_2 { + virtual void m(); +} __attribute__((trivial_abi)); // expected-warning {{'trivial_abi' cannot be applied to 'S3_2'}} + struct S4 { int a; }; -- 2.40.0