[clang] [analyzer] Fix false positive on `UnreachableCode` with CTU mode (PR #219225)
Donát Nagy via cfe-commits
cfe-commits at lists.llvm.org
Fri Aug 28 02:41:54 PDT 2026
================
@@ -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
----------------
NagyDonat wrote:
> I fear that CTU was enabled here, but was ineffective. Could you demonstrate that this in fact enables CTU that does work. Demonstrate it by a CTU report.
According to the `CoreEngine` constructor code, enabling CTU always creates a `CTUWorkList` even if there are actually no other relevant translation units. I'm convinced that this test does correctly validate the intended behavior – but you are right that perhaps it would be nice to showcase a CTU report (e.g. by copying a trivial test from one of the CTU test files) as a visible demonstration.
> Could you also demonstrate that the `alpha.deadcode.UnreachableCode` works otherwise to establish a baseline that its effective.
This is tested in other test files (or at least I very much hope so :sweat_smile:), but I'm not opposed to having a trivial test that produces an `UnreachableCode` report.
https://github.com/llvm/llvm-project/pull/219225
More information about the cfe-commits
mailing list