diff options
author | Ted Kremenek <kremenek@apple.com> | 2014-03-05 23:46:07 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2014-03-05 23:46:07 +0000 |
commit | 0a69cabd35f18294c75dcf768f7f5442f2f802d7 (patch) | |
tree | 9af5b0a2de69b1ba954fe747f1ceeb9f186ac1a3 /clang/lib/Analysis/ReachableCode.cpp | |
parent | 6766f8d23bcb9d17f2694b962fb9ba44cb048232 (diff) | |
download | bcm5719-llvm-0a69cabd35f18294c75dcf768f7f5442f2f802d7.tar.gz bcm5719-llvm-0a69cabd35f18294c75dcf768f7f5442f2f802d7.zip |
[-Wunreachable-code] generalize pruning out warning on trivial returns.
Previously we only pruned dead returns preceded by a call to a
'noreturn' function. After looking at the results of the LLVM codebase,
there are many others that should be pruned as well.
llvm-svn: 203029
Diffstat (limited to 'clang/lib/Analysis/ReachableCode.cpp')
-rw-r--r-- | clang/lib/Analysis/ReachableCode.cpp | 15 |
1 files changed, 6 insertions, 9 deletions
diff --git a/clang/lib/Analysis/ReachableCode.cpp b/clang/lib/Analysis/ReachableCode.cpp index b772145456e..7958840b89d 100644 --- a/clang/lib/Analysis/ReachableCode.cpp +++ b/clang/lib/Analysis/ReachableCode.cpp @@ -291,12 +291,12 @@ static bool isEnumConstant(const Expr *Ex) { } static bool isTrivialExpression(const Expr *Ex) { + Ex = Ex->IgnoreParenCasts(); return isa<IntegerLiteral>(Ex) || isa<StringLiteral>(Ex) || isEnumConstant(Ex); } -static bool isTrivialReturnPrecededByNoReturn(const CFGBlock *B, - const Stmt *S) { +static bool isTrivialReturn(const CFGBlock *B, const Stmt *S) { if (B->pred_empty()) return false; @@ -304,8 +304,6 @@ static bool isTrivialReturnPrecededByNoReturn(const CFGBlock *B, if (!Ex) return false; - Ex = Ex->IgnoreParenCasts(); - if (!isTrivialExpression(Ex)) return false; @@ -319,14 +317,13 @@ static bool isTrivialReturnPrecededByNoReturn(const CFGBlock *B, if (const ReturnStmt *RS = dyn_cast<ReturnStmt>(CS->getStmt())) { const Expr *RE = RS->getRetValue(); if (RE && RE->IgnoreParenCasts() == Ex) - break; + return true; } - return false; + break; } } - assert(B->pred_size() == 1); - return bodyEndsWithNoReturn(*B->pred_begin()); + return false; } void DeadCodeScan::reportDeadCode(const CFGBlock *B, @@ -339,7 +336,7 @@ void DeadCodeScan::reportDeadCode(const CFGBlock *B, return; // Suppress trivial 'return' statements that are dead. - if (isTrivialReturnPrecededByNoReturn(B, S)) + if (isTrivialReturn(B, S)) return; SourceRange R1, R2; |