[clang] [WIP][analyzer] Use canonical step identification in conjureSymbol (PR #239219)
DonĂ¡t Nagy via cfe-commits
cfe-commits at lists.llvm.org
Thu Nov 5 05:03:02 PST 2026
https://github.com/NagyDonat created https://github.com/llvm/llvm-project/pull/239219
Conjured symbols are distinguished by the combination of a StackFrame, a CFGElementRef and a VisitCount. These are currently passed around as arguments in long and confusing call chains; but it would be much better if each conjureSymbol call would query the current canonical values from ExprEngine.
This commit prototypizes this and asserts that the canonical values agree with the ones received through the traditional process.
This is a prototype, some tests are failing, do not merge!
>From 095eb13ed73ca3700197cfb689f7600232f32012 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Don=C3=A1t=20Nagy?= <donat.nagy at ericsson.com>
Date: Thu, 5 Nov 2026 13:57:07 +0100
Subject: [PATCH] [WIP][analyzer] Use canonical step identification in
conjureSymbol
Conjured symbols are distinguished by the combination of a StackFrame, a
CFGElementRef and a VisitCount. These are currently passed around as
arguments in long and confusing call chains; but it would be much better
if each conjureSymbol call would query the current canonical values from
ExprEngine.
This commit prototypizes this and asserts that the canonical values
agree with the ones received through the traditional process.
This is a prototype, some tests are failing, do not merge!
---
.../Core/PathSensitive/SymbolManager.h | 31 +++++++++++++++++++
clang/lib/StaticAnalyzer/Core/ExprEngine.cpp | 16 ++++++++++
2 files changed, 47 insertions(+)
diff --git a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h
index 62eda2aae0171c..e4e09c6fde0bed 100644
--- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h
+++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h
@@ -39,6 +39,7 @@ namespace ento {
class BasicValueFactory;
class StoreManager;
+class ExprEngine;
///A symbol representing the value stored at a MemRegion.
class SymbolRegionValue : public SymbolData {
@@ -505,6 +506,20 @@ class SymExprAllocator {
SymbolID nextID() { return NextSymbolID++; }
};
+/// To conjure symbols, the SymbolManager needs to query the canonical
+/// identifiers of the current analysis step from the ExprEngine (which queries
+/// the visit count from the BlockCounter of the WorkList).
+///
+class AccessToCurrAnalysisStep {
+ const ExprEngine *EE = nullptr;
+
+public:
+ void setExprEngine(const ExprEngine *P) { EE = P; }
+ const StackFrame *getCurrStackFrame() const;
+ ConstCFGElementRef getCFGElementRef() const;
+ unsigned getNumVisitedCurrent() const;
+};
+
class SymbolManager {
using DataSetTy = llvm::FoldingSet<SymExpr>;
using SymbolDependTy =
@@ -520,11 +535,17 @@ class SymbolManager {
BasicValueFactory &BV;
ASTContext &Ctx;
+ AccessToCurrAnalysisStep CurrStep;
+
public:
SymbolManager(ASTContext &ctx, BasicValueFactory &bv,
llvm::BumpPtrAllocator &bpalloc)
: SymbolDependencies(16), Alloc(bpalloc), BV(bv), Ctx(ctx) {}
+ void initAccessToCurrAnalysisStep(ExprEngine *EE) {
+ CurrStep.setExprEngine(EE);
+ }
+
static bool canSymbolicate(QualType T);
/// Create or retrieve a SymExpr of type \p SymExprT for the given arguments.
@@ -537,10 +558,20 @@ class SymbolManager {
const StackFrame *SF, QualType T,
unsigned VisitCount,
const void *SymbolTag = nullptr) {
+ assert(Elem == CurrStep.getCFGElementRef());
+ assert(SF == CurrStep.getCurrStackFrame());
+ assert(VisitCount == CurrStep.getNumVisitedCurrent());
return acquire<SymbolConjured>(Elem, SF, T, VisitCount, SymbolTag);
}
+ const SymbolConjured *conjureSymbol(QualType T,
+ const void *SymbolTag = nullptr) {
+ return conjureSymbol(CurrStep.getCFGElementRef(),
+ CurrStep.getCurrStackFrame(), T,
+ CurrStep.getNumVisitedCurrent(), SymbolTag);
+ }
+
QualType getType(const SymExpr *SE) const {
return SE->getType();
}
diff --git a/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp b/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
index 1fe3dc0986b886..e5dc442a223474 100644
--- a/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
+++ b/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
@@ -232,6 +232,7 @@ ExprEngine::ExprEngine(cross_tu::CrossTranslationUnitContext &CTU,
svalBuilder(StateMgr.getSValBuilder()), ObjCNoRet(mgr.getASTContext()),
BR(mgr, *this), VisitedCallees(VisitedCalleesIn),
HowToInline(HowToInlineIn) {
+ SymMgr.initAccessToCurrAnalysisStep(this);
unsigned TrimInterval = mgr.options.GraphTrimInterval;
if (TrimInterval != 0) {
// Enable eager node reclamation when constructing the ExplodedGraph.
@@ -4009,3 +4010,18 @@ void ExprEngine::ConstructInitList(const Expr *E, ArrayRef<Expr *> Args,
}
Dst.insert(Engine.makeNodeWithBinding(Pred, E, Val));
}
+
+const StackFrame *AccessToCurrAnalysisStep::getCurrStackFrame() const {
+ assert(EE && "Constructor of ExprEngine should have initialized this!");
+ return EE->getCurrStackFrame();
+}
+
+ConstCFGElementRef AccessToCurrAnalysisStep::getCFGElementRef() const {
+ assert(EE && "Constructor of ExprEngine should have initialized this!");
+ return EE->getCFGElementRef();
+}
+
+unsigned AccessToCurrAnalysisStep::getNumVisitedCurrent() const {
+ assert(EE && "Constructor of ExprEngine should have initialized this!");
+ return EE->getNumVisitedCurrent();
+}
More information about the cfe-commits
mailing list