[clang] [analyzer] Turn NodeBuilderContext into a class (PR #84638)
Diego A. Estrada Rivera via cfe-commits
cfe-commits at lists.llvm.org
Tue Mar 12 06:42:21 PDT 2024
https://github.com/diego-est updated https://github.com/llvm/llvm-project/pull/84638
>From 114e22388508cd1ef5174bdda041564691b58032 Mon Sep 17 00:00:00 2001
From: Sunglas <diego.estrada1 at proton.me>
Date: Sat, 9 Mar 2024 12:23:43 -0400
Subject: [PATCH 1/3] [analyzer] Turn NodeBuilderContext into a class
---
.../clang/StaticAnalyzer/Core/PathSensitive/CoreEngine.h | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CoreEngine.h b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CoreEngine.h
index 8e392421fef9bb..24d4afc551355e 100644
--- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CoreEngine.h
+++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CoreEngine.h
@@ -59,7 +59,7 @@ class CoreEngine {
friend class ExprEngine;
friend class IndirectGotoNodeBuilder;
friend class NodeBuilder;
- friend struct NodeBuilderContext;
+ friend class NodeBuilderContext;
friend class SwitchNodeBuilder;
public:
@@ -194,7 +194,8 @@ class CoreEngine {
};
// TODO: Turn into a class.
-struct NodeBuilderContext {
+class NodeBuilderContext {
+public:
const CoreEngine &Eng;
const CFGBlock *Block;
const LocationContext *LC;
>From a87c924670e00e293ea31d5230c6131509ce26b1 Mon Sep 17 00:00:00 2001
From: Sunglas <diego.estrada1 at proton.me>
Date: Sun, 10 Mar 2024 21:24:23 -0400
Subject: [PATCH 2/3] fix(NodeBuilderContext implementation): changed class
members to private and added the appropriate getters.
Moved every member in NodeBuilderContext to private and added the following getters:
- getEngine
- getLocationContext
Setters are not necessary since the class members are const already.
---
.../clang/StaticAnalyzer/Core/PathSensitive/CoreEngine.h | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CoreEngine.h b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CoreEngine.h
index 24d4afc551355e..0705affa4117d9 100644
--- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CoreEngine.h
+++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CoreEngine.h
@@ -195,11 +195,11 @@ class CoreEngine {
// TODO: Turn into a class.
class NodeBuilderContext {
-public:
const CoreEngine &Eng;
const CFGBlock *Block;
const LocationContext *LC;
+public:
NodeBuilderContext(const CoreEngine &E, const CFGBlock *B,
const LocationContext *L)
: Eng(E), Block(B), LC(L) {
@@ -209,9 +209,15 @@ class NodeBuilderContext {
NodeBuilderContext(const CoreEngine &E, const CFGBlock *B, ExplodedNode *N)
: NodeBuilderContext(E, B, N->getLocationContext()) {}
+ /// Return the CoreEngine associated with this builder.
+ const CoreEngine &getEngine() const { return Eng; }
+
/// Return the CFGBlock associated with this builder.
const CFGBlock *getBlock() const { return Block; }
+ /// Return the location context associated with this builder.
+ const LocationContext *getLocationContext() const { return LC; }
+
/// Returns the number of times the current basic block has been
/// visited on the exploded graph path.
unsigned blockCount() const {
>From 0d4adf0600c1a86b092fec52749bd781e0ecfd6d Mon Sep 17 00:00:00 2001
From: Sunglas <diego.estrada1 at proton.me>
Date: Tue, 12 Mar 2024 07:33:34 -0400
Subject: [PATCH 3/3] fix(NodeBuilderContext API): fixed accesses to
NodeBuilderContext private member accesses.
The files CheckerManager.h, CoreEngine.h, ExprEngine.h and CoreEngine.cpp all had bad private member accesses.
---
clang/include/clang/StaticAnalyzer/Core/CheckerManager.h | 2 +-
.../clang/StaticAnalyzer/Core/PathSensitive/CoreEngine.h | 1 -
.../clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h | 2 +-
clang/lib/StaticAnalyzer/Core/CoreEngine.cpp | 6 +++---
4 files changed, 5 insertions(+), 6 deletions(-)
diff --git a/clang/include/clang/StaticAnalyzer/Core/CheckerManager.h b/clang/include/clang/StaticAnalyzer/Core/CheckerManager.h
index a45ba1bc573e1e..ad25d18f280700 100644
--- a/clang/include/clang/StaticAnalyzer/Core/CheckerManager.h
+++ b/clang/include/clang/StaticAnalyzer/Core/CheckerManager.h
@@ -49,7 +49,7 @@ class ExplodedNodeSet;
class ExprEngine;
struct EvalCallOptions;
class MemRegion;
-struct NodeBuilderContext;
+class NodeBuilderContext;
class ObjCMethodCall;
class RegionAndSymbolInvalidationTraits;
class SVal;
diff --git a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CoreEngine.h b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CoreEngine.h
index 0705affa4117d9..0ef353bf9731ca 100644
--- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CoreEngine.h
+++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CoreEngine.h
@@ -193,7 +193,6 @@ class CoreEngine {
DataTag::Factory &getDataTags() { return DataTags; }
};
-// TODO: Turn into a class.
class NodeBuilderContext {
const CoreEngine &Eng;
const CFGBlock *Block;
diff --git a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
index f7894fb83ce65c..859c1497d7e6db 100644
--- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
+++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
@@ -85,7 +85,7 @@ class ExplodedNodeSet;
class ExplodedNode;
class IndirectGotoNodeBuilder;
class MemRegion;
-struct NodeBuilderContext;
+class NodeBuilderContext;
class NodeBuilderWithSinks;
class ProgramState;
class ProgramStateManager;
diff --git a/clang/lib/StaticAnalyzer/Core/CoreEngine.cpp b/clang/lib/StaticAnalyzer/Core/CoreEngine.cpp
index 141d0cb320bffa..c141e26508fcc3 100644
--- a/clang/lib/StaticAnalyzer/Core/CoreEngine.cpp
+++ b/clang/lib/StaticAnalyzer/Core/CoreEngine.cpp
@@ -625,8 +625,8 @@ ExplodedNode* NodeBuilder::generateNodeImpl(const ProgramPoint &Loc,
bool MarkAsSink) {
HasGeneratedNodes = true;
bool IsNew;
- ExplodedNode *N = C.Eng.G.getNode(Loc, State, MarkAsSink, &IsNew);
- N->addPredecessor(FromN, C.Eng.G);
+ ExplodedNode *N = C.getEngine().G.getNode(Loc, State, MarkAsSink, &IsNew);
+ N->addPredecessor(FromN, C.getEngine().G);
Frontier.erase(FromN);
if (!IsNew)
@@ -655,7 +655,7 @@ ExplodedNode *BranchNodeBuilder::generateNode(ProgramStateRef State,
if (!isFeasible(branch))
return nullptr;
- ProgramPoint Loc = BlockEdge(C.Block, branch ? DstT:DstF,
+ ProgramPoint Loc = BlockEdge(C.getBlock(), branch ? DstT:DstF,
NodePred->getLocationContext());
ExplodedNode *Succ = generateNodeImpl(Loc, State, NodePred);
return Succ;
More information about the cfe-commits
mailing list