[cfe-commits] r138854 - in /cfe/trunk: include/clang/AST/Decl.h include/clang/Basic/DiagnosticSemaKinds.td lib/AST/ASTDiagnostic.cpp lib/Sema/AnalysisBasedWarnings.cpp test/Sema/return-noreturn.c test/SemaCXX/warn-missing-noreturn.cpp test/SemaObjC/return.m

Chandler Carruth chandlerc at gmail.com
Wed Aug 31 02:01:53 PDT 2011


Author: chandlerc
Date: Wed Aug 31 04:01:53 2011
New Revision: 138854

URL: http://llvm.org/viewvc/llvm-project?rev=138854&view=rev
Log:
Improve the diagnostic text for -Wmissing-noreturn to include the name
of the function in question when applicable (that is, not for blocks).
Patch by Joerg Sonnenberger with some stylistic tweaks by me.

When discussing this weth Joerg, streaming the decl directly into the
diagnostic didn't work because we have a pointer-to-const, and the
overload doesn't accept such. In order to make my style tweaks to the
patch, I first changed the overload to accept a pointer-to-const, and
then changed the diagnostic printing layer to also use
a pointer-to-const, cleaning up a gross line of code along the way.

Modified:
    cfe/trunk/include/clang/AST/Decl.h
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/trunk/lib/AST/ASTDiagnostic.cpp
    cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp
    cfe/trunk/test/Sema/return-noreturn.c
    cfe/trunk/test/SemaCXX/warn-missing-noreturn.cpp
    cfe/trunk/test/SemaObjC/return.m

Modified: cfe/trunk/include/clang/AST/Decl.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=138854&r1=138853&r2=138854&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Decl.h (original)
+++ cfe/trunk/include/clang/AST/Decl.h Wed Aug 31 04:01:53 2011
@@ -3030,7 +3030,7 @@
 /// Insertion operator for diagnostics.  This allows sending NamedDecl's
 /// into a diagnostic with <<.
 inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
-                                           NamedDecl* ND) {
+                                           const NamedDecl* ND) {
   DB.AddTaggedVal(reinterpret_cast<intptr_t>(ND), Diagnostic::ak_nameddecl);
   return DB;
 }

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=138854&r1=138853&r2=138854&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Wed Aug 31 04:01:53 2011
@@ -236,10 +236,10 @@
 def err_falloff_nonvoid_block : Error<
   "control reaches end of non-void block">;
 def warn_suggest_noreturn_function : Warning<
-  "function could be attribute 'noreturn'">,
+  "function %0 could be declared with attribute 'noreturn'">,
   InGroup<DiagGroup<"missing-noreturn">>, DefaultIgnore;
 def warn_suggest_noreturn_block : Warning<
-  "block could be attribute 'noreturn'">,
+  "block could be declared with attribute 'noreturn'">,
   InGroup<DiagGroup<"missing-noreturn">>, DefaultIgnore;
 def warn_unreachable : Warning<"will never be executed">,
   InGroup<DiagGroup<"unreachable-code">>, DefaultIgnore;

Modified: cfe/trunk/lib/AST/ASTDiagnostic.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTDiagnostic.cpp?rev=138854&r1=138853&r2=138854&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ASTDiagnostic.cpp (original)
+++ cfe/trunk/lib/AST/ASTDiagnostic.cpp Wed Aug 31 04:01:53 2011
@@ -269,8 +269,8 @@
                "Invalid modifier for NamedDecl* argument");
         Qualified = false;
       }
-      reinterpret_cast<NamedDecl*>(Val)->
-      getNameForDiagnostic(S, Context.PrintingPolicy, Qualified);
+      const NamedDecl *ND = reinterpret_cast<const NamedDecl*>(Val);
+      ND->getNameForDiagnostic(S, Context.PrintingPolicy, Qualified);
       break;
     }
     case Diagnostic::ak_nestednamespec: {

Modified: cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp?rev=138854&r1=138853&r2=138854&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp (original)
+++ cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp Wed Aug 31 04:01:53 2011
@@ -376,9 +376,14 @@
                  CD.diag_AlwaysFallThrough_ReturnsNonVoid);
         break;
       case NeverFallThroughOrReturn:
-        if (ReturnsVoid && !HasNoReturn && CD.diag_NeverFallThroughOrReturn)
-          S.Diag(Compound->getLBracLoc(),
-                 CD.diag_NeverFallThroughOrReturn);
+        if (ReturnsVoid && !HasNoReturn && CD.diag_NeverFallThroughOrReturn) {
+          if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
+            S.Diag(Compound->getLBracLoc(), CD.diag_NeverFallThroughOrReturn)
+              << FD;
+          } else {
+            S.Diag(Compound->getLBracLoc(), CD.diag_NeverFallThroughOrReturn);
+          }
+        }
         break;
       case NeverFallThrough:
         break;

Modified: cfe/trunk/test/Sema/return-noreturn.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/return-noreturn.c?rev=138854&r1=138853&r2=138854&view=diff
==============================================================================
--- cfe/trunk/test/Sema/return-noreturn.c (original)
+++ cfe/trunk/test/Sema/return-noreturn.c Wed Aug 31 04:01:53 2011
@@ -1,8 +1,8 @@
 // RUN: %clang_cc1 %s -fsyntax-only -verify -fblocks -Wmissing-noreturn -Wno-unreachable-code
 
 int j;
-void test1() { // expected-warning {{function could be attribute 'noreturn'}}
-  ^ (void) { while (1) { } }(); // expected-warning {{block could be attribute 'noreturn'}}
+void test1() { // expected-warning {{function 'test1' could be declared with attribute 'noreturn'}}
+  ^ (void) { while (1) { } }(); // expected-warning {{block could be declared with attribute 'noreturn'}}
   ^ (void) { if (j) while (1) { } }();
   while (1) { }
 }

Modified: cfe/trunk/test/SemaCXX/warn-missing-noreturn.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-missing-noreturn.cpp?rev=138854&r1=138853&r2=138854&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/warn-missing-noreturn.cpp (original)
+++ cfe/trunk/test/SemaCXX/warn-missing-noreturn.cpp Wed Aug 31 04:01:53 2011
@@ -1,14 +1,14 @@
 // RUN: %clang_cc1 -fsyntax-only -verify %s -Wmissing-noreturn -Wreturn-type
 void f() __attribute__((noreturn));
 
-template<typename T> void g(T) { // expected-warning {{function could be attribute 'noreturn'}}
+template<typename T> void g(T) { // expected-warning {{function 'g<int>' could be declared with attribute 'noreturn'}}
   f();
 }
 
 template void g<int>(int); // expected-note {{in instantiation of function template specialization 'g<int>' requested here}}
 
 template<typename T> struct A {
-  void g() { // expected-warning {{function could be attribute 'noreturn'}}
+  void g() { // expected-warning {{function 'g' could be declared with attribute 'noreturn'}}
     f();
   }
 };
@@ -16,7 +16,7 @@
 template struct A<int>; // expected-note {{in instantiation of member function 'A<int>::g' requested here}}
 
 struct B {
-  template<typename T> void g(T) { // expected-warning {{function could be attribute 'noreturn'}}
+  template<typename T> void g(T) { // expected-warning {{function 'g<int>' could be declared with attribute 'noreturn'}}
     f();
   }
 };
@@ -61,7 +61,7 @@
     void *f;
 
     A() : f(0) { }
-    A(int) : f(h()) { } // expected-warning {{function could be attribute 'noreturn'}}
+    A(int) : f(h()) { } // expected-warning {{function 'A' could be declared with attribute 'noreturn'}}
     A(char) : f(j()) { }
     A(bool b) : f(b ? h() : j()) { }
   };

Modified: cfe/trunk/test/SemaObjC/return.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/return.m?rev=138854&r1=138853&r2=138854&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/return.m (original)
+++ cfe/trunk/test/SemaObjC/return.m Wed Aug 31 04:01:53 2011
@@ -14,7 +14,7 @@
 }
 
 // PR5286
-void test3(int a) {  // expected-warning {{function could be attribute 'noreturn'}}
+void test3(int a) {  // expected-warning {{function 'test3' could be declared with attribute 'noreturn'}}
   while (1) {
     if (a)
       @throw (id)0;





More information about the cfe-commits mailing list