[clang] [analyzer] Fix false positive on `UnreachableCode` with CTU mode (PR #219225)

Marco Milanese via cfe-commits cfe-commits at lists.llvm.org
Thu Aug 27 08:09:02 PDT 2026


https://github.com/marco-milanese-sonarsource updated https://github.com/llvm/llvm-project/pull/219225

>From 59f08b836ae562a43939d8317b5855bafed5e2c0 Mon Sep 17 00:00:00 2001
From: Marco Milanese <marco.milanese at sonarsource.com>
Date: Thu, 27 Aug 2026 16:42:47 +0200
Subject: [PATCH] Add regression test

---
 clang/test/Analysis/ctu/stu-workremaining.cpp | 21 +++++++++++++++++++
 1 file changed, 21 insertions(+)
 create mode 100644 clang/test/Analysis/ctu/stu-workremaining.cpp

diff --git a/clang/test/Analysis/ctu/stu-workremaining.cpp b/clang/test/Analysis/ctu/stu-workremaining.cpp
new file mode 100644
index 0000000000000..1524a98ec9a93
--- /dev/null
+++ b/clang/test/Analysis/ctu/stu-workremaining.cpp
@@ -0,0 +1,21 @@
+// RUN: %clang_analyze_cc1 -std=c++20 \
+// RUN:   -analyzer-checker=core,alpha.deadcode.UnreachableCode \
+// RUN:   -analyzer-config experimental-enable-naive-ctu-analysis=true \
+// RUN:   -analyzer-config max-nodes=10 \
+// RUN:   -verify=ctu-on %s
+// ctu-on-no-diagnostics
+
+// RUN: %clang_analyze_cc1 -std=c++20 \
+// RUN:   -analyzer-checker=core,alpha.deadcode.UnreachableCode \
+// RUN:   -analyzer-config experimental-enable-naive-ctu-analysis=false \
+// RUN:   -analyzer-config max-nodes=10 \
+// RUN:   -verify=ctu-off %s
+// ctu-off-no-diagnostics
+
+#define NOP ((void)0)
+
+void entrypoint(int x) {
+  NOP; NOP; NOP; NOP; NOP;
+  NOP; NOP; NOP; NOP; NOP;
+  if (x) NOP;
+}



More information about the cfe-commits mailing list