https://github.com/a-tarasyuk updated 
https://github.com/llvm/llvm-project/pull/183194

>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 1/2] [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();

>From 37a1882626b635de94df740bcfdb558904fc5f16 Mon Sep 17 00:00:00 2001
From: Oleksandr Tarasiuk <[email protected]>
Date: Wed, 25 Feb 2026 15:16:24 +0200
Subject: [PATCH 2/2] fix thread-safety false positives after CFG try changes

---
 clang/lib/Analysis/ThreadSafety.cpp           |  8 ++++++++
 .../SemaCXX/warn-thread-safety-analysis.cpp   | 20 +++++++++++++++++++
 2 files changed, 28 insertions(+)

diff --git a/clang/lib/Analysis/ThreadSafety.cpp 
b/clang/lib/Analysis/ThreadSafety.cpp
index 2c5976af9f61d..671f709b409ce 100644
--- a/clang/lib/Analysis/ThreadSafety.cpp
+++ b/clang/lib/Analysis/ThreadSafety.cpp
@@ -2782,6 +2782,11 @@ void 
ThreadSafetyAnalyzer::runAnalysis(AnalysisDeclContext &AC) {
       if (neverReturns(*PI) || !PrevBlockInfo->Reachable)
         continue;
 
+      const Stmt *TS = (*PI)->getTerminatorStmt();
+      if (isa_and_nonnull<CXXTryStmt>(TS) &&
+          isa_and_nonnull<CXXCatchStmt>(CurrBlock->getLabel()))
+        continue;
+
       // Okay, we can reach this block from the entry.
       CurrBlockInfo->Reachable = true;
 
@@ -2879,6 +2884,9 @@ void 
ThreadSafetyAnalyzer::runAnalysis(AnalysisDeclContext &AC) {
       if (*SI == nullptr || !VisitedBlocks.alreadySet(*SI))
         continue;
 
+      if (isa_and_nonnull<CXXTryStmt>(CurrBlock->getTerminatorStmt()))
+        continue;
+
       CFGBlock *FirstLoopBlock = *SI;
       CFGBlockInfo *PreLoop = &BlockInfo[FirstLoopBlock->getBlockID()];
       CFGBlockInfo *LoopEnd = &BlockInfo[CurrBlockID];
diff --git a/clang/test/SemaCXX/warn-thread-safety-analysis.cpp 
b/clang/test/SemaCXX/warn-thread-safety-analysis.cpp
index a6c9a2236fc45..61c9ef0d490cc 100644
--- a/clang/test/SemaCXX/warn-thread-safety-analysis.cpp
+++ b/clang/test/SemaCXX/warn-thread-safety-analysis.cpp
@@ -7831,3 +7831,23 @@ void test3() {
 }
 
 } // namespace WideStringLiteral
+
+namespace GH182822 {
+struct S {
+  Mutex mu;
+  int v GUARDED_BY(mu);
+};
+
+void test(S *s, int v) {
+  s->mu.Lock();
+  try {
+    if (v) {
+      try {}
+      catch (int) {}
+    }
+  }
+  catch (...) { }
+  s->v = 1;
+  s->mu.Unlock();
+}
+}

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to