Skip to content

Commit 8fe21fd

Browse files
authored
[clang][analyzer] Ignore try-statements in UnreachableCode checker (#91675)
Fixes #90162
1 parent e7d09ce commit 8fe21fd

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

clang/lib/StaticAnalyzer/Checkers/UnreachableCodeChecker.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,8 @@ void UnreachableCodeChecker::checkEndAnalysis(ExplodedGraph &G,
159159
SL = DL.asLocation();
160160
if (SR.isInvalid() || !SL.isValid())
161161
continue;
162+
if (isa<CXXTryStmt>(S))
163+
continue;
162164
}
163165
else
164166
continue;
@@ -254,4 +256,4 @@ void ento::registerUnreachableCodeChecker(CheckerManager &mgr) {
254256

255257
bool ento::shouldRegisterUnreachableCodeChecker(const CheckerManager &mgr) {
256258
return true;
257-
}
259+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// RUN: %clang_analyze_cc1 -verify %s -fcxx-exceptions -fexceptions -analyzer-checker=core,alpha.deadcode.UnreachableCode
2+
3+
// expected-no-diagnostics
4+
5+
void foo();
6+
7+
void fp_90162() {
8+
try { // no-warning: The TryStmt shouldn't be unreachable.
9+
foo();
10+
} catch (int) {
11+
foo(); // We assume that catch handlers are reachable.
12+
}
13+
}

0 commit comments

Comments
 (0)