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 <[email protected]>
Date: Thu, 27 Aug 2026 16:42:47 +0200
Subject: [PATCH 1/3] 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;
+}

>From 0cad94e9c5d5918005f1d45a057b7641acd224a0 Mon Sep 17 00:00:00 2001
From: Marco Milanese <[email protected]>
Date: Thu, 27 Aug 2026 17:47:59 +0200
Subject: [PATCH 2/3] Track whether STU finished with work remaining

---
 .../clang/StaticAnalyzer/Core/PathSensitive/CoreEngine.h     | 5 +++++
 clang/lib/StaticAnalyzer/Core/CoreEngine.cpp                 | 1 +
 2 files changed, 6 insertions(+)

diff --git a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CoreEngine.h 
b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CoreEngine.h
index d26c0d9257b0f..a5c24dd97e3d2 100644
--- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CoreEngine.h
+++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CoreEngine.h
@@ -82,6 +82,10 @@ class CoreEngine {
   /// usually because it could not reason about something.
   BlocksAborted blocksAborted;
 
+  /// Whether the single-TU phase ran out of budget with work left over.
+  /// The CTU phase replaces \c WList, so this has to be remembered separately.
+  bool STUHadWorkRemaining = false;
+
   /// The information about functions shared by the whole translation unit.
   /// (This data is owned by AnalysisConsumer.)
   FunctionSummariesTy *FunctionSummaries;
@@ -148,6 +152,7 @@ class CoreEngine {
   bool wasBlocksExhausted() const { return !blocksExhausted.empty(); }
   bool hasWorkRemaining() const { return wasBlocksExhausted() ||
                                          WList->hasWork() ||
+                                         STUHadWorkRemaining ||
                                          wasBlockAborted(); }
 
   /// Inform the CoreEngine that a basic block was aborted because
diff --git a/clang/lib/StaticAnalyzer/Core/CoreEngine.cpp 
b/clang/lib/StaticAnalyzer/Core/CoreEngine.cpp
index 307c96b23b206..85fddd16057a9 100644
--- a/clang/lib/StaticAnalyzer/Core/CoreEngine.cpp
+++ b/clang/lib/StaticAnalyzer/Core/CoreEngine.cpp
@@ -161,6 +161,7 @@ bool CoreEngine::ExecuteWorkList(const StackFrame *SF, 
unsigned MaxSteps,
     return MaxSteps - Steps;
   };
   const unsigned STUSteps = ProcessWList(MaxSteps);
+  STUHadWorkRemaining = WList->hasWork();
 
   if (CTUWList) {
     NumSTUSteps += STUSteps;

>From 098a10f514f865b557e1cd5ccf9a799ec61dab4b Mon Sep 17 00:00:00 2001
From: Marco Milanese <[email protected]>
Date: Fri, 28 Aug 2026 08:52:26 +0200
Subject: [PATCH 3/3] Fix formatting issue

---
 .../clang/StaticAnalyzer/Core/PathSensitive/CoreEngine.h  | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CoreEngine.h 
b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CoreEngine.h
index a5c24dd97e3d2..46399793306b8 100644
--- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CoreEngine.h
+++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CoreEngine.h
@@ -150,10 +150,10 @@ class CoreEngine {
   // Functions for external checking of whether we have unfinished work.
   bool wasBlockAborted() const { return !blocksAborted.empty(); }
   bool wasBlocksExhausted() const { return !blocksExhausted.empty(); }
-  bool hasWorkRemaining() const { return wasBlocksExhausted() ||
-                                         WList->hasWork() ||
-                                         STUHadWorkRemaining ||
-                                         wasBlockAborted(); }
+  bool hasWorkRemaining() const {
+    return wasBlocksExhausted() || WList->hasWork() || STUHadWorkRemaining ||
+           wasBlockAborted();
+  }
 
   /// Inform the CoreEngine that a basic block was aborted because
   /// it could not be completely analyzed.

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

Reply via email to