https://github.com/a-tarasyuk created https://github.com/llvm/llvm-project/pull/183194
Fixes #182822 --- This patch fixes a _false positive_ regression of `-Wimplicit-fallthrough`, caused by a CFG `try` change in 41c566e, which led to `CXXTryStmt` predecessor edges being considered in `switch` _fallthrough_ analysis and incorrectly treated as normal _fallthrough_. >From a9055f54e6408f4534ec4612c3a2f3b1acb66577 Mon Sep 17 00:00:00 2001 From: Oleksandr Tarasiuk <[email protected]> Date: Wed, 25 Feb 2026 00:34:47 +0200 Subject: [PATCH] [Clang] fix -Wimplicit-fallthrough false positive after try CFG changes --- clang/lib/Sema/AnalysisBasedWarnings.cpp | 4 ++-- .../SemaCXX/switch-implicit-fallthrough.cpp | 19 +++++++++++++++++-- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/clang/lib/Sema/AnalysisBasedWarnings.cpp b/clang/lib/Sema/AnalysisBasedWarnings.cpp index 5c49e601840cf..1e604b6b6e26f 100644 --- a/clang/lib/Sema/AnalysisBasedWarnings.cpp +++ b/clang/lib/Sema/AnalysisBasedWarnings.cpp @@ -1252,8 +1252,8 @@ class FallthroughMapper : public DynamicRecursiveASTVisitor { continue; const Stmt *Term = P->getTerminatorStmt(); - if (isa_and_nonnull<SwitchStmt>(Term)) - continue; // Switch statement, good. + if (isa_and_nonnull<SwitchStmt, CXXTryStmt>(Term)) + continue; // switch/try terminators are not switch fallthrough edges const SwitchCase *SW = dyn_cast_or_null<SwitchCase>(P->getLabel()); if (SW && SW->getSubStmt() == B.getLabel() && P->begin() == P->end()) diff --git a/clang/test/SemaCXX/switch-implicit-fallthrough.cpp b/clang/test/SemaCXX/switch-implicit-fallthrough.cpp index 750663717b66a..8b26d7766ca79 100644 --- a/clang/test/SemaCXX/switch-implicit-fallthrough.cpp +++ b/clang/test/SemaCXX/switch-implicit-fallthrough.cpp @@ -1,5 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 -Wimplicit-fallthrough -Wunreachable-code-fallthrough %s - +// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 -Wimplicit-fallthrough -Wunreachable-code-fallthrough -fcxx-exceptions %s int fallthrough(int n) { switch (n / 10) { @@ -292,6 +291,22 @@ void fallthrough_in_lambda() { }; } +namespace GH182822 { + void test(int n) { + switch (n) { + case 0: + try { + if (n) { + try { + } catch (int) { + } + } + } catch (...) { + } + } + } +} + namespace PR18983 { void fatal() __attribute__((noreturn)); int num(); _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
