[PATCH] D131065: [clang][dataflow] Store DeclContext of block being analysed in Environment if available.
weiyi via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Aug 3 04:09:10 PDT 2022
wyt created this revision.
Herald added subscribers: martong, tschuett, xazax.hun.
Herald added a reviewer: NoQ.
Herald added a project: All.
wyt requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D131065
Files:
clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
Index: clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
===================================================================
--- clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
+++ clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
@@ -154,7 +154,7 @@
: DACtx(&DACtx), FlowConditionToken(&DACtx.makeFlowConditionToken()) {}
Environment::Environment(const Environment &Other)
- : DACtx(Other.DACtx), DeclToLoc(Other.DeclToLoc),
+ : DACtx(Other.DACtx), DeclCtx(Other.DeclCtx), DeclToLoc(Other.DeclToLoc),
ExprToLoc(Other.ExprToLoc), LocToVal(Other.LocToVal),
MemberLocToStruct(Other.MemberLocToStruct),
FlowConditionToken(&DACtx->forkFlowCondition(*Other.FlowConditionToken)) {
@@ -167,9 +167,11 @@
}
Environment::Environment(DataflowAnalysisContext &DACtx,
- const DeclContext &DeclCtx)
+ const DeclContext &DeclCtxArg)
: Environment(DACtx) {
- if (const auto *FuncDecl = dyn_cast<FunctionDecl>(&DeclCtx)) {
+ DeclCtx = &DeclCtxArg;
+
+ if (const auto *FuncDecl = dyn_cast<FunctionDecl>(DeclCtx)) {
assert(FuncDecl->getBody() != nullptr);
initGlobalVars(*FuncDecl->getBody(), *this);
for (const auto *ParamDecl : FuncDecl->parameters()) {
@@ -181,7 +183,7 @@
}
}
- if (const auto *MethodDecl = dyn_cast<CXXMethodDecl>(&DeclCtx)) {
+ if (const auto *MethodDecl = dyn_cast<CXXMethodDecl>(DeclCtx)) {
auto *Parent = MethodDecl->getParent();
assert(Parent != nullptr);
if (Parent->isLambda())
@@ -268,12 +270,14 @@
LatticeJoinEffect Environment::join(const Environment &Other,
Environment::ValueModel &Model) {
- assert(DACtx == Other.DACtx);
+ assert(DACtx == Other.DACtx && DeclCtx == Other.DeclCtx);
auto Effect = LatticeJoinEffect::Unchanged;
Environment JoinedEnv(*DACtx);
+ JoinedEnv.DeclCtx = DeclCtx;
+
JoinedEnv.DeclToLoc = intersectDenseMaps(DeclToLoc, Other.DeclToLoc);
if (DeclToLoc.size() != JoinedEnv.DeclToLoc.size())
Effect = LatticeJoinEffect::Changed;
Index: clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
===================================================================
--- clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
+++ clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
@@ -167,6 +167,10 @@
LatticeJoinEffect join(const Environment &Other,
Environment::ValueModel &Model);
+ /// Returns the `DeclCtx` of the block being analysed if provided, otherwise
+ /// returns nullptr.
+ const DeclContext *getDeclCtx() { return DeclCtx; }
+
// FIXME: Rename `createOrGetStorageLocation` to `getOrCreateStorageLocation`,
// `getStableStorageLocation`, or something more appropriate.
@@ -363,6 +367,9 @@
// `DACtx` is not null and not owned by this object.
DataflowAnalysisContext *DACtx;
+ // `DeclCtx` of the block being analysed if provided.
+ const DeclContext *DeclCtx;
+
// Maps from program declarations and statements to storage locations that are
// assigned to them. Unlike the maps in `DataflowAnalysisContext`, these
// include only storage locations that are in scope for a particular basic
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D131065.449626.patch
Type: text/x-patch
Size: 3251 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220803/4b7431e7/attachment.bin>
More information about the cfe-commits
mailing list