[PATCH] NoReturn Warning: Removed Warning for Unreachable Return

Michael Bao mike.h.bao at gmail.com
Sat Jan 25 18:06:04 PST 2014


  Ping. Updated for Rev 199220.

  Removed getDeclName.

http://llvm-reviews.chandlerc.com/D2508

CHANGE SINCE LAST DIFF
  http://llvm-reviews.chandlerc.com/D2508?vs=6445&id=6664#toc

Files:
  lib/Sema/SemaStmt.cpp
  test/Sema/return-noreturn.c

Index: lib/Sema/SemaStmt.cpp
===================================================================
--- lib/Sema/SemaStmt.cpp
+++ lib/Sema/SemaStmt.cpp
@@ -2810,12 +2810,9 @@
   bool isObjCMethod = false;
 
   if (const FunctionDecl *FD = getCurFunctionDecl()) {
-    FnRetType = FD->getReturnType();
+    FnRetType = FD->getResultType();
     if (FD->hasAttrs())
       Attrs = &FD->getAttrs();
-    if (FD->isNoReturn())
-      Diag(ReturnLoc, diag::warn_noreturn_function_has_return_expr)
-        << FD->getDeclName();
   } else if (ObjCMethodDecl *MD = getCurMethodDecl()) {
     FnRetType = MD->getReturnType();
     isObjCMethod = true;
@@ -2994,6 +2991,12 @@
       !CurContext->isDependentContext())
     FunctionScopes.back()->Returns.push_back(Result);
 
+  if (const FunctionDecl *FD = getCurFunctionDecl()) {
+    if (FD->isNoReturn()) 
+      DiagRuntimeBehavior(ReturnLoc, Result,
+        PDiag(diag::warn_noreturn_function_has_return_expr) << FD);
+  }
+
   return Owned(Result);
 }
 
Index: test/Sema/return-noreturn.c
===================================================================
--- test/Sema/return-noreturn.c
+++ test/Sema/return-noreturn.c
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 %s -fsyntax-only -verify -fblocks -Wmissing-noreturn -Wno-unreachable-code
+// RUN: %clang_cc1 %s -fsyntax-only -verify -fblocks -Wmissing-noreturn -Wno-unreachable-code -Winvalid-noreturn
 
 int j;
 void test1() { // expected-warning {{function 'test1' could be declared with attribute 'noreturn'}}
@@ -40,3 +40,11 @@
 _Noreturn void test5() {
   test2_positive();
 }
+
+// Should not warn about an invalid return even if the function is 
+// marked 'noreturn' and a return statement is present 
+// in the case that the return statement is unreachable.
+__attribute__((noreturn)) void test6() {
+  while (1) {}  
+  return;
+}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D2508.3.patch
Type: text/x-patch
Size: 1831 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140125/63bac9e0/attachment.bin>


More information about the cfe-commits mailing list