[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
diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp
index e21f380..7a7e037 100644
--- a/lib/Sema/SemaDeclCXX.cpp
+++ b/lib/Sema/SemaDeclCXX.cpp
@@ -6018,6 +6018,10 @@
}
}
+ // See if trivial_abi has to be dropped.
+ if (Record->hasAttr<TrivialABIAttr>())
+ checkIllFormedTrivialABIStruct(*Record);
+
// Set HasTrivialSpecialMemberForCall if the record has attribute
// "trivial_abi".
bool HasTrivialABI = Record->hasAttr<TrivialABIAttr>();
@@ -7810,17 +7814,12 @@
l->getName();
}
- // See if trivial_abi has to be dropped.
- auto *RD = dyn_cast<CXXRecordDecl>(TagDecl);
- if (RD && RD->hasAttr<TrivialABIAttr>())
- checkIllFormedTrivialABIStruct(*RD);
-
ActOnFields(S, RLoc, TagDecl, llvm::makeArrayRef(
// strict aliasing violation!
reinterpret_cast<Decl**>(FieldCollector->getCurFields()),
FieldCollector->getCurNumFields()), LBrac, RBrac, AttrList);
- CheckCompletedCXXClass(RD);
+ CheckCompletedCXXClass(dyn_cast_or_null<CXXRecordDecl>(TagDecl));
}
/// AddImplicitlyDeclaredMembersToClass - Adds any implicitly-declared
diff --git a/lib/Sema/SemaTemplateInstantiate.cpp b/lib/Sema/SemaTemplateInstantiate.cpp
index ebda251..2218bdd 100644
--- a/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/lib/Sema/SemaTemplateInstantiate.cpp
@@ -2123,10 +2123,6 @@
}
}
- // See if trivial_abi has to be dropped.
- if (Instantiation && Instantiation->hasAttr<TrivialABIAttr>())
- 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 c83a94d..fe8baee 100644
--- a/test/SemaObjCXX/attr-trivial-abi.mm
+++ b/test/SemaObjCXX/attr-trivial-abi.mm
@@ -18,6 +18,10 @@
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;
};