r203333 - [-Wunreachable-code] Handle 'return' with no argument dominated by 'noreturn' function.

Ted Kremenek kremenek at apple.com
Fri Mar 7 18:22:23 PST 2014


Author: kremenek
Date: Fri Mar  7 20:22:23 2014
New Revision: 203333

URL: http://llvm.org/viewvc/llvm-project?rev=203333&view=rev
Log:
[-Wunreachable-code] Handle 'return' with no argument dominated by 'noreturn' function.

Modified:
    cfe/trunk/lib/Analysis/ReachableCode.cpp
    cfe/trunk/test/Sema/warn-unreachable.c

Modified: cfe/trunk/lib/Analysis/ReachableCode.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/ReachableCode.cpp?rev=203333&r1=203332&r2=203333&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/ReachableCode.cpp (original)
+++ cfe/trunk/lib/Analysis/ReachableCode.cpp Fri Mar  7 20:22:23 2014
@@ -132,10 +132,8 @@ static bool isTrivialExpression(const Ex
 
 static bool isTrivialReturnOrDoWhile(const CFGBlock *B, const Stmt *S) {
   const Expr *Ex = dyn_cast<Expr>(S);
-  if (!Ex)
-    return false;
 
-  if (!isTrivialExpression(Ex))
+  if (Ex && !isTrivialExpression(Ex))
     return false;
 
   // Check if the block ends with a do...while() and see if 'S' is the
@@ -152,13 +150,20 @@ static bool isTrivialReturnOrDoWhile(con
   // Look to see if the block ends with a 'return', and see if 'S'
   // is a substatement.  The 'return' may not be the last element in
   // the block because of destructors.
-  assert(!B->empty());
   for (CFGBlock::const_reverse_iterator I = B->rbegin(), E = B->rend();
        I != E; ++I) {
     if (Optional<CFGStmt> CS = I->getAs<CFGStmt>()) {
       if (const ReturnStmt *RS = dyn_cast<ReturnStmt>(CS->getStmt())) {
-        const Expr *RE = RS->getRetValue();
-        if (RE && stripExprSugar(RE->IgnoreParenCasts()) == Ex)
+        bool LookAtBody = false;
+        if (RS == S)
+          LookAtBody = true;
+        else {
+          const Expr *RE = RS->getRetValue();
+          if (RE && stripExprSugar(RE->IgnoreParenCasts()) == Ex)
+            LookAtBody = true;
+        }
+
+        if (LookAtBody)
           return bodyEndsWithNoReturn(*B->pred_begin());
       }
       break;

Modified: cfe/trunk/test/Sema/warn-unreachable.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/warn-unreachable.c?rev=203333&r1=203332&r2=203333&view=diff
==============================================================================
--- cfe/trunk/test/Sema/warn-unreachable.c (original)
+++ cfe/trunk/test/Sema/warn-unreachable.c Fri Mar  7 20:22:23 2014
@@ -199,6 +199,11 @@ int trivial_dead_return() {
   return ((0)); // no-warning
 }
 
+void trivial_dead_return_void() {
+  raze();
+  return; // no-warning
+}
+
 MyEnum trival_dead_return_enum() {
   raze();
   return Value1; // no-warning





More information about the cfe-commits mailing list