]> granicus.if.org Git - clang/commitdiff
[-Wunreachable-code] Teach reachable code analysis heuristics about more literal...
authorTed Kremenek <kremenek@apple.com>
Fri, 7 Mar 2014 02:25:50 +0000 (02:25 +0000)
committerTed Kremenek <kremenek@apple.com>
Fri, 7 Mar 2014 02:25:50 +0000 (02:25 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@203193 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Analysis/ReachableCode.cpp
test/Sema/warn-unreachable.c
test/SemaCXX/warn-unreachable.cpp

index 45930c0e2d975067e83c762c4c2aa94205c03a3f..fa31dc1b0682a330dcb2c9865d16f6d9f03720f8 100644 (file)
@@ -343,6 +343,8 @@ static const Expr *stripExprSugar(const Expr *Ex) {
 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);
 }
 
index 289d74336c9fe613341c9a4da37bf76211015edf..4df2ec6dcc6a24a4e40688798d9cca81b36967e4 100644 (file)
@@ -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
 }
 
index 1fbe15c0f023b5b43862e03454dfd62928b084e9..1030c993ada7ed31b6ae0ae8f3540fa900a217b1 100644 (file)
@@ -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
+}