llvmorg-github-actions[bot] wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang-static-analyzer-1

Author: Gábor Horváth (Xazax-hun)

<details>
<summary>Changes</summary>

ProgramStateManager::addGDM stored {Key: nullptr} when a trait became empty, 
e.g. after removing the last element of a map/set, or after setting a scalar or 
pointer trait to 0/nullptr (ExprEngine does this with 
LastEagerlyAssumeExprIfSuccessful on every eager assume). Every trait reads a 
null entry the same way as an absent one, so these states had identical 
contents but a different GDM, and were uniqued as distinct ProgramStates. Paths 
that should have merged in the ExplodedGraph did not.

Remove the key when the new value is null, so that "absent" and "empty" have 
one canonical representation.

On some LLVM TUs (GVN, LiveVariables, RegionStore) the analyzer now executes 
0.8-4.2% fewer steps and explores 3-24% fewer paths. On those TUs and SemaExpr 
this reduces the instructions of the static analyzer by 0.8-2.6% and the cycles 
by 1.4-3.1%. Peak memory is unchanged except LiveVariables (-4.8%). The 
diagnostics are unchanged.

Assisted-by: Claude Opus 5.5

---
Full diff: https://github.com/llvm/llvm-project/pull/244845.diff


1 Files Affected:

- (modified) clang/lib/StaticAnalyzer/Core/ProgramState.cpp (+5) 


``````````diff
diff --git a/clang/lib/StaticAnalyzer/Core/ProgramState.cpp 
b/clang/lib/StaticAnalyzer/Core/ProgramState.cpp
index 123f4f7958d72..2a4d2de0cf225 100644
--- a/clang/lib/StaticAnalyzer/Core/ProgramState.cpp
+++ b/clang/lib/StaticAnalyzer/Core/ProgramState.cpp
@@ -541,6 +541,11 @@ void *ProgramStateManager::FindGDMContext(
 
 ProgramStateRef ProgramStateManager::addGDM(ProgramStateRef St, const void 
*Key,
                                             void *Data) {
+  // A null value is indistinguishable from an absent entry for every trait, so
+  // remove the key to keep a single canonical representation of the state.
+  if (!Data)
+    return removeGDM(St, Key);
+
   ProgramState::GenericDataMap M1 = St->getGDM();
   ProgramState::GenericDataMap M2 = GDMFactory.add(M1, Key, Data);
 

``````````

</details>


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

Reply via email to