]> granicus.if.org Git - clang/commitdiff
[Sema] Produce diagnostics for attribute 'trivial_abi' that appears
authorAkira Hatanaka <ahatanaka@apple.com>
Tue, 19 Jun 2018 05:04:44 +0000 (05:04 +0000)
committerAkira Hatanaka <ahatanaka@apple.com>
Tue, 19 Jun 2018 05:04:44 +0000 (05:04 +0000)
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
lib/Sema/SemaTemplateInstantiate.cpp
test/SemaObjCXX/attr-trivial-abi.mm

index e21f380fb71f79963cb134a14ccff6fd1a260de3..7a7e0378cfdca69085f9e50c4be279d91b930272 100644 (file)
@@ -6018,6 +6018,10 @@ void Sema::CheckCompletedCXXClass(CXXRecordDecl *Record) {
     }
   }
 
+  // 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 @@ void Sema::ActOnFinishCXXMemberSpecification(Scope* S, SourceLocation RLoc,
       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
index ebda251c64eff584d5f5fc4e4c295dc897d1bf28..2218bdd958e6d5c7dfd0c6c754c2930486d24705 100644 (file)
@@ -2123,10 +2123,6 @@ Sema::InstantiateClass(SourceLocation PointOfInstantiation,
     }
   }
 
-  // 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);
index c83a94dcd98c69ef4411bd76785af6321f01b2f2..fe8baee473e9b5d28187dc30f3018dbfd326a5d3 100644 (file)
@@ -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;
 };