From 70c6a065aa0c40d263ea0d8d904ac9fa20cedb2d Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Tue, 4 Mar 2014 21:41:38 +0000 Subject: [PATCH] [-Wunreachable-code] handle cases where a dead 'return' may have a valid predecessor. Fies PR19040. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@202892 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Analysis/ReachableCode.cpp | 5 +++++ test/SemaCXX/warn-unreachable.cpp | 23 +++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/lib/Analysis/ReachableCode.cpp b/lib/Analysis/ReachableCode.cpp index 4a192802e7..b0e9250426 100644 --- a/lib/Analysis/ReachableCode.cpp +++ b/lib/Analysis/ReachableCode.cpp @@ -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); diff --git a/test/SemaCXX/warn-unreachable.cpp b/test/SemaCXX/warn-unreachable.cpp index dd071258e2..dbbcc8c50e 100644 --- a/test/SemaCXX/warn-unreachable.cpp +++ b/test/SemaCXX/warn-unreachable.cpp @@ -107,3 +107,26 @@ template <> void funcToSpecialize() { 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}} +} + + -- 2.40.0