]> granicus.if.org Git - clang/commitdiff
Attribute noreturn is now put in declaration attributes. Fixed a double warning gener...
authorAbramo Bagnara <abramo.bagnara@gmail.com>
Fri, 30 Apr 2010 09:13:03 +0000 (09:13 +0000)
committerAbramo Bagnara <abramo.bagnara@gmail.com>
Fri, 30 Apr 2010 09:13:03 +0000 (09:13 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@102705 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaDeclAttr.cpp
lib/Sema/SemaType.cpp
test/Sema/attr-noreturn.c

index ccc0c2df989758cb6dff7aa4cf980e467ec79318..52d9f58d3726402412eca16024b2ab8d9e020744 100644 (file)
@@ -467,10 +467,11 @@ static void HandleMallocAttr(Decl *d, const AttributeList &Attr, Sema &S) {
 }
 
 static bool HandleCommonNoReturnAttr(Decl *d, const AttributeList &Attr,
-                                     Sema &S) {
+                                     Sema &S, bool EmitDiagnostics) {
   // check the attribute arguments.
   if (Attr.getNumArgs() != 0) {
-    S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments) << 0;
+    if (EmitDiagnostics)
+      S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments) << 0;
     return false;
   }
 
@@ -478,10 +479,11 @@ static bool HandleCommonNoReturnAttr(Decl *d, const AttributeList &Attr,
     ValueDecl *VD = dyn_cast<ValueDecl>(d);
     if (VD == 0 || (!VD->getType()->isBlockPointerType()
                     && !VD->getType()->isFunctionPointerType())) {
-      S.Diag(Attr.getLoc(),
-             Attr.isCXX0XAttribute() ? diag::err_attribute_wrong_decl_type
-                                     : diag::warn_attribute_wrong_decl_type)
-        << Attr.getName() << 0 /*function*/;
+      if (EmitDiagnostics)
+        S.Diag(Attr.getLoc(),
+               Attr.isCXX0XAttribute() ? diag::err_attribute_wrong_decl_type
+                                       : diag::warn_attribute_wrong_decl_type)
+          << Attr.getName() << 0 /*function*/;
       return false;
     }
   }
@@ -490,21 +492,17 @@ static bool HandleCommonNoReturnAttr(Decl *d, const AttributeList &Attr,
 }
 
 static void HandleNoReturnAttr(Decl *d, const AttributeList &Attr, Sema &S) {
-  // NOTE: We don't add the attribute to a FunctionDecl because the noreturn
-  //  trait will be part of the function's type.
-
-  // Don't apply as a decl attribute to ValueDecl.
-  // FIXME: probably ought to diagnose this.
-  if (isa<ValueDecl>(d))
-    return;
-
-  if (HandleCommonNoReturnAttr(d, Attr, S))
+  /*
+    Do check for well-formedness, but do not emit diagnostics:
+    it was already emitted by Sema::ProcessFnAttr().
+  */
+  if (HandleCommonNoReturnAttr(d, Attr, S, /*EmitDiagnostic=*/false))
     d->addAttr(::new (S.Context) NoReturnAttr());
 }
 
 static void HandleAnalyzerNoReturnAttr(Decl *d, const AttributeList &Attr,
                                        Sema &S) {
-  if (HandleCommonNoReturnAttr(d, Attr, S))
+  if (HandleCommonNoReturnAttr(d, Attr, S, true))
     d->addAttr(::new (S.Context) AnalyzerNoReturnAttr());
 }
 
index 882784b60273229c148ce2cddc734e97fe009912..dc78fd633f630bfba57ccf34237e50028de45958 100644 (file)
@@ -1912,8 +1912,8 @@ void ProcessTypeAttributeList(Sema &S, QualType &Result,
   // type, but others can be present in the type specifiers even though they
   // apply to the decl.  Here we apply type attributes and ignore the rest.
   for (; AL; AL = AL->getNext()) {
-    // If this is an attribute we can handle, do so now, otherwise, add it to
-    // the LeftOverAttrs list for rechaining.
+    // If this is an attribute we can handle, do so now,
+    // otherwise, add it to the FnAttrs list for rechaining.
     switch (AL->getKind()) {
     default: break;
 
index b17f9fd12920dc7b4b537661524322e8a29b67e2..5333a2c13fc28e7d13473360b0baeb483a5c5343 100644 (file)
@@ -40,3 +40,5 @@ f5 (unsigned long size)
 __attribute__((noreturn)) void f(__attribute__((noreturn)) void (*x)(void)) {
   x();
 }
+
+typedef void (*Fun)(void) __attribute__ ((noreturn(2))); // expected-error {{attribute requires 0 argument(s)}}