[clang] [analyzer] Import CTU constant initializers on demand (PR #231393)

DonĂ¡t Nagy via cfe-commits cfe-commits at lists.llvm.org
Wed Oct 14 05:15:19 PDT 2026


================
@@ -731,6 +702,11 @@ void AnalysisConsumer::HandleCode(Decl *D, AnalysisMode Mode,
   if (Mgr->getAnalysisDeclContext(D)->isBodyAutosynthesized())
     return;
 
+  // CFG pruning and AST-based checks need these values before Store reads.
+  if (Opts.IsNaiveCTUEnabled && (Mode & AM_Syntax))
+    CTU.importReferencedInitializers(
+        D->getBody(), Opts.CTUDir, Opts.CTUIndexName, Opts.DisplayCTUProgress);
----------------
NagyDonat wrote:

> An unused declaration alone no longer triggers an import.

This is an important improvement, and skipping unevaluated code is also useful.

> However, yes, this preparation can still exhaust the shared CTU budget before function definitions are requested. In fact, the condition is `AM_Syntax`, rather than whether any AST-based checker is enabled, so it can also happen with only path-sensitive checkers enabled. This patch removes the imports caused by unused declarations; it does not establish priority for function imports.

This is perfectly acceptable for now. 

> A checker opt-in or more targeted preparation would be worth considering in a follow-up. We would also need to account for CFG pruning, since removing this preparation outright would lose the existing dead-store behavior.

This can happen in follow-up patches if the budget exhaustion still causes trouble after merging this PR.

https://github.com/llvm/llvm-project/pull/231393


More information about the cfe-commits mailing list