Skip to content

Commit 8d3c960

Browse files
committed
Revert "[clang][dataflow] Store DeclContext of block being analysed in Environment if available."
Use of uninitialized memory. https://lab.llvm.org/buildbot/#/builders/74/builds/12713 This reverts commit 8a4c40b.
1 parent 7587065 commit 8d3c960

File tree

2 files changed

+10
-27
lines changed

2 files changed

+10
-27
lines changed

clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -347,13 +347,6 @@ class Environment {
347347
/// imply that `Val` is true.
348348
bool flowConditionImplies(BoolValue &Val) const;
349349

350-
/// Returns the `DeclContext` of the block being analysed, if any. Otherwise,
351-
/// returns null.
352-
const DeclContext *getDeclCtx() { return DeclCtx; }
353-
354-
/// Sets the `DeclContext` of the block being analysed.
355-
void setDeclCtx(const DeclContext *Ctx) { DeclCtx = Ctx; }
356-
357350
/// Returns the `ControlFlowContext` registered for `F`, if any. Otherwise,
358351
/// returns null.
359352
const ControlFlowContext *getControlFlowContext(const FunctionDecl *F) {
@@ -384,9 +377,6 @@ class Environment {
384377
// `DACtx` is not null and not owned by this object.
385378
DataflowAnalysisContext *DACtx;
386379

387-
// `DeclContext` of the block being analysed if provided.
388-
const DeclContext *DeclCtx;
389-
390380
// In a properly initialized `Environment`, `ReturnLoc` should only be null if
391381
// its `DeclContext` could not be cast to a `FunctionDecl`.
392382
StorageLocation *ReturnLoc = nullptr;

clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ Environment::Environment(DataflowAnalysisContext &DACtx)
154154
: DACtx(&DACtx), FlowConditionToken(&DACtx.makeFlowConditionToken()) {}
155155

156156
Environment::Environment(const Environment &Other)
157-
: DACtx(Other.DACtx), DeclCtx(Other.DeclCtx), ReturnLoc(Other.ReturnLoc),
157+
: DACtx(Other.DACtx), ReturnLoc(Other.ReturnLoc),
158158
ThisPointeeLoc(Other.ThisPointeeLoc), DeclToLoc(Other.DeclToLoc),
159159
ExprToLoc(Other.ExprToLoc), LocToVal(Other.LocToVal),
160160
MemberLocToStruct(Other.MemberLocToStruct),
@@ -168,11 +168,9 @@ Environment &Environment::operator=(const Environment &Other) {
168168
}
169169

170170
Environment::Environment(DataflowAnalysisContext &DACtx,
171-
const DeclContext &DeclCtxArg)
171+
const DeclContext &DeclCtx)
172172
: Environment(DACtx) {
173-
setDeclCtx(&DeclCtxArg);
174-
175-
if (const auto *FuncDecl = dyn_cast<FunctionDecl>(DeclCtx)) {
173+
if (const auto *FuncDecl = dyn_cast<FunctionDecl>(&DeclCtx)) {
176174
assert(FuncDecl->getBody() != nullptr);
177175
initGlobalVars(*FuncDecl->getBody(), *this);
178176
for (const auto *ParamDecl : FuncDecl->parameters()) {
@@ -187,7 +185,7 @@ Environment::Environment(DataflowAnalysisContext &DACtx,
187185
ReturnLoc = &createStorageLocation(ReturnType);
188186
}
189187

190-
if (const auto *MethodDecl = dyn_cast<CXXMethodDecl>(DeclCtx)) {
188+
if (const auto *MethodDecl = dyn_cast<CXXMethodDecl>(&DeclCtx)) {
191189
auto *Parent = MethodDecl->getParent();
192190
assert(Parent != nullptr);
193191
if (Parent->isLambda())
@@ -212,9 +210,6 @@ Environment Environment::pushCall(const CallExpr *Call) const {
212210

213211
const auto *FuncDecl = Call->getDirectCallee();
214212
assert(FuncDecl != nullptr);
215-
216-
Env.setDeclCtx(FuncDecl);
217-
218213
// FIXME: In order to allow the callee to reference globals, we probably need
219214
// to call `initGlobalVars` here in some way.
220215

@@ -257,12 +252,12 @@ Environment Environment::pushCall(const CallExpr *Call) const {
257252

258253
void Environment::popCall(const Environment &CalleeEnv) {
259254
// We ignore `DACtx` because it's already the same in both. We don't want the
260-
// callee's `DeclCtx`, `ReturnLoc` or `ThisPointeeLoc`. We don't bring back
261-
// `DeclToLoc` and `ExprToLoc` because we want to be able to later analyze the
262-
// same callee in a different context, and `setStorageLocation` requires there
263-
// to not already be a storage location assigned. Conceptually, these maps
264-
// capture information from the local scope, so when popping that scope, we do
265-
// not propagate the maps.
255+
// callee's `ReturnLoc` or `ThisPointeeLoc`. We don't bring back `DeclToLoc`
256+
// and `ExprToLoc` because we want to be able to later analyze the same callee
257+
// in a different context, and `setStorageLocation` requires there to not
258+
// already be a storage location assigned. Conceptually, these maps capture
259+
// information from the local scope, so when popping that scope, we do not
260+
// propagate the maps.
266261
this->LocToVal = std::move(CalleeEnv.LocToVal);
267262
this->MemberLocToStruct = std::move(CalleeEnv.MemberLocToStruct);
268263
this->FlowConditionToken = std::move(CalleeEnv.FlowConditionToken);
@@ -309,13 +304,11 @@ LatticeJoinEffect Environment::join(const Environment &Other,
309304
assert(DACtx == Other.DACtx);
310305
assert(ReturnLoc == Other.ReturnLoc);
311306
assert(ThisPointeeLoc == Other.ThisPointeeLoc);
312-
assert(DeclCtx == Other.DeclCtx);
313307

314308
auto Effect = LatticeJoinEffect::Unchanged;
315309

316310
Environment JoinedEnv(*DACtx);
317311

318-
JoinedEnv.setDeclCtx(DeclCtx);
319312
JoinedEnv.ReturnLoc = ReturnLoc;
320313
JoinedEnv.ThisPointeeLoc = ThisPointeeLoc;
321314

0 commit comments

Comments
 (0)