r203193 - [-Wunreachable-code] Teach reachable code analysis heuristics about more literal types.
Ted Kremenek
kremenek at apple.com
Thu Mar 6 18:25:50 PST 2014
Author: kremenek
Date: Thu Mar 6 20:25:50 2014
New Revision: 203193
URL: http://llvm.org/viewvc/llvm-project?rev=203193&view=rev
Log:
[-Wunreachable-code] Teach reachable code analysis heuristics about more literal types.
Modified:
cfe/trunk/lib/Analysis/ReachableCode.cpp
cfe/trunk/test/Sema/warn-unreachable.c
cfe/trunk/test/SemaCXX/warn-unreachable.cpp
Modified: cfe/trunk/lib/Analysis/ReachableCode.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/ReachableCode.cpp?rev=203193&r1=203192&r2=203193&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/ReachableCode.cpp (original)
+++ cfe/trunk/lib/Analysis/ReachableCode.cpp Thu Mar 6 20:25:50 2014
@@ -343,6 +343,8 @@ static const Expr *stripExprSugar(const
static bool isTrivialExpression(const Expr *Ex) {
Ex = Ex->IgnoreParenCasts();
return isa<IntegerLiteral>(Ex) || isa<StringLiteral>(Ex) ||
+ isa<CXXBoolLiteralExpr>(Ex) || isa<ObjCBoolLiteralExpr>(Ex) ||
+ isa<CharacterLiteral>(Ex) ||
isEnumConstant(Ex);
}
Modified: cfe/trunk/test/Sema/warn-unreachable.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/warn-unreachable.c?rev=203193&r1=203192&r2=203193&view=diff
==============================================================================
--- cfe/trunk/test/Sema/warn-unreachable.c (original)
+++ cfe/trunk/test/Sema/warn-unreachable.c Thu Mar 6 20:25:50 2014
@@ -215,6 +215,16 @@ MyEnum trivial_dead_return_enum_2(int x)
return 2; // expected-warning {{will never be executed}}
}
+const char *trivial_dead_return_cstr() {
+ raze();
+ return ""; // no-warning
+}
+
+char trivial_dead_return_char() {
+ raze();
+ return ' '; // no-warning
+}
+
MyEnum nontrivial_dead_return_enum_2(int x) {
switch (x) {
case 1: return 1;
@@ -260,11 +270,13 @@ int test_config_constant(int x) {
calledFun(); // expected-warning {{will never be executed}}
}
-int sizeof_int() {
+int sizeof_int(int x, int y) {
if (sizeof(long) == sizeof(int))
return 1; // no-warning
if (sizeof(long) != sizeof(int))
return 0; // no-warning
+ if (x && y && sizeof(long) > sizeof(int))
+ return 0;
return 2; // no-warning
}
Modified: cfe/trunk/test/SemaCXX/warn-unreachable.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-unreachable.cpp?rev=203193&r1=203192&r2=203193&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/warn-unreachable.cpp (original)
+++ cfe/trunk/test/SemaCXX/warn-unreachable.cpp Thu Mar 6 20:25:50 2014
@@ -150,4 +150,8 @@ std::string testStrWarn(const char *s) {
return s; // expected-warning {{will never be executed}}
}
+bool testBool() {
+ raze();
+ return true; // no-warning
+}
More information about the cfe-commits
mailing list