[cfe-commits] r72669 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaStmt.cpp test/Sema/attr-noreturn.c

Chris Lattner sabre at nondot.org
Sun May 31 12:32:14 PDT 2009


Author: lattner
Date: Sun May 31 14:32:13 2009
New Revision: 72669

URL: http://llvm.org/viewvc/llvm-project?rev=72669&view=rev
Log:
Downgrade an error about "return in a no-return function" from being 
an error to being a warning that defaults to error.  If you want this to
be a warning, you have to explicitly pass -Winvalid-noreturn to clang to
map it back to a warning.

Modified:
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/trunk/lib/Sema/SemaStmt.cpp
    cfe/trunk/test/Sema/attr-noreturn.c

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=72669&r1=72668&r2=72669&view=diff

==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Sun May 31 14:32:13 2009
@@ -1736,8 +1736,9 @@
   InGroup<ReturnType>;
 def ext_return_has_void_expr : Extension<
   "void %select{function|method}1 %0 should not return void expression">;
-def err_noreturn_function_has_return_expr : Error<
-  "function %0 declared 'noreturn' should not return">;
+def warn_noreturn_function_has_return_expr : Warning<
+  "function %0 declared 'noreturn' should not return">, DefaultError,
+  InGroup<DiagGroup<"invalid-noreturn">>;
 def err_noreturn_block_has_return_expr : Error<
   "block declared 'noreturn' should not return">;
 def err_block_on_nonlocal : Error<

Modified: cfe/trunk/lib/Sema/SemaStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaStmt.cpp?rev=72669&r1=72668&r2=72669&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaStmt.cpp (original)
+++ cfe/trunk/lib/Sema/SemaStmt.cpp Sun May 31 14:32:13 2009
@@ -834,11 +834,9 @@
   QualType FnRetType;
   if (const FunctionDecl *FD = getCurFunctionDecl()) {
     FnRetType = FD->getResultType();
-    if (FD->hasAttr<NoReturnAttr>()) {
-      Diag(ReturnLoc, diag::err_noreturn_function_has_return_expr)
+    if (FD->hasAttr<NoReturnAttr>())
+      Diag(ReturnLoc, diag::warn_noreturn_function_has_return_expr)
         << getCurFunctionOrMethodDecl()->getDeclName();
-      return StmtError();
-    }
   } else if (ObjCMethodDecl *MD = getCurMethodDecl())
     FnRetType = MD->getResultType();
   else // If we don't have a function/method context, bail.

Modified: cfe/trunk/test/Sema/attr-noreturn.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/attr-noreturn.c?rev=72669&r1=72668&r2=72669&view=diff

==============================================================================
--- cfe/trunk/test/Sema/attr-noreturn.c (original)
+++ cfe/trunk/test/Sema/attr-noreturn.c Sun May 31 14:32:13 2009
@@ -14,8 +14,14 @@
 int f2() __attribute__((noreturn(1, 2))); // expected-error {{attribute requires 0 argument(s)}}
 
 void f3() __attribute__((noreturn));
-
 void f3() {
   return;  // expected-error {{function 'f3' declared 'noreturn' should not return}}
 }
 
+#pragma clang diagnostic warning "-Winvalid-noreturn"
+
+void f4() __attribute__((noreturn));
+void f4() {
+  return;  // expected-warning {{function 'f4' declared 'noreturn' should not return}}
+}
+





More information about the cfe-commits mailing list