https://github.com/Xazax-hun created
https://github.com/llvm/llvm-project/pull/244845
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
From b8d8cde7fd9b09ab5a49be0ca0ac902b8baa784f Mon Sep 17 00:00:00 2001
From: Gabor Horvath <[email protected]>
Date: Sat, 21 Nov 2026 02:51:56 +0000
Subject: [PATCH] [analyzer] Remove GDM entries instead of storing null
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
---
clang/lib/StaticAnalyzer/Core/ProgramState.cpp | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/clang/lib/StaticAnalyzer/Core/ProgramState.cpp
b/clang/lib/StaticAnalyzer/Core/ProgramState.cpp
index 123f4f7958d725..2a4d2de0cf225a 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);
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits