]> granicus.if.org Git - clang/commitdiff
[-Wunreachable-code] handle cases where a dead 'return' may have a valid predecessor.
authorTed Kremenek <kremenek@apple.com>
Tue, 4 Mar 2014 21:41:38 +0000 (21:41 +0000)
committerTed Kremenek <kremenek@apple.com>
Tue, 4 Mar 2014 21:41:38 +0000 (21:41 +0000)
Fies PR19040.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@202892 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 4a192802e7166f5afd327e4c12cbe8ef789263e7..b0e92504260b4cbdf05a1d5ea9df5b2a5474e4e1 100644 (file)
@@ -263,6 +263,11 @@ static bool bodyEndsWithNoReturn(const CFGBlock *B) {
 }
 
 static bool bodyEndsWithNoReturn(const CFGBlock::AdjacentBlock &AB) {
+  // If the predecessor is a normal CFG edge, then by definition
+  // the predecessor did not end with a 'noreturn'.
+  if (AB.getReachableBlock())
+    return false;
+
   const CFGBlock *Pred = AB.getPossiblyUnreachableBlock();
   assert(!AB.isReachable() && Pred);
   return bodyEndsWithNoReturn(Pred);
index dd071258e29d16faafe50816fbb530c076730804..dbbcc8c50e0bad486e82c6da4105ad9a112025d6 100644 (file)
@@ -107,3 +107,26 @@ template <> void funcToSpecialize<int>() {
   dead(); // expected-warning {{will never be executed}}
 }
 
+// Handle 'try' code dominating a dead return.
+enum PR19040_test_return_t
+{ PR19040_TEST_FAILURE };
+namespace PR19040_libtest
+{
+  class A {
+  public:
+    ~A ();
+  };
+}
+PR19040_test_return_t PR19040_fn1 ()
+{
+    try
+    {
+        throw PR19040_libtest::A ();
+    } catch (...)
+    {
+        return PR19040_TEST_FAILURE;
+    }
+    return PR19040_TEST_FAILURE; // expected-warning {{will never be executed}}
+}
+
+