Skip to content

Commit 27e78e6

Browse files
authored
[clang][dataflow] Remove a deprecated CachedConstAccessorsLattice API (#127001)
We've already migrated known users from the old to the new version of getOrCreateConstMethodReturnStorageLocation. The conversion is pretty straightforward as well, if there are out-of-tree users: Previously: use CallExpr as argument New: get the direct Callee from CallExpr, null check, and use that as the argument instead.
1 parent 1e64ea9 commit 27e78e6

File tree

2 files changed

+18
-81
lines changed

2 files changed

+18
-81
lines changed

clang/include/clang/Analysis/FlowSensitive/CachedConstAccessorsLattice.h

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -63,23 +63,6 @@ template <typename Base> class CachedConstAccessorsLattice : public Base {
6363
getOrCreateConstMethodReturnValue(const RecordStorageLocation &RecordLoc,
6464
const CallExpr *CE, Environment &Env);
6565

66-
/// Creates or returns a previously created `StorageLocation` associated with
67-
/// a const method call `obj.getFoo()` where `RecordLoc` is the
68-
/// `RecordStorageLocation` of `obj`.
69-
///
70-
/// The callback `Initialize` runs on the storage location if newly created.
71-
/// Returns nullptr if unable to find or create a value.
72-
///
73-
/// Requirements:
74-
///
75-
/// - `CE` should return a location (GLValue or a record type).
76-
///
77-
/// DEPRECATED: switch users to the below overload which takes Callee and Type
78-
/// directly.
79-
StorageLocation *getOrCreateConstMethodReturnStorageLocation(
80-
const RecordStorageLocation &RecordLoc, const CallExpr *CE,
81-
Environment &Env, llvm::function_ref<void(StorageLocation &)> Initialize);
82-
8366
/// Creates or returns a previously created `StorageLocation` associated with
8467
/// a const method call `obj.getFoo()` where `RecordLoc` is the
8568
/// `RecordStorageLocation` of `obj`, `Callee` is the decl for `getFoo`.
@@ -208,29 +191,6 @@ Value *CachedConstAccessorsLattice<Base>::getOrCreateConstMethodReturnValue(
208191
return Val;
209192
}
210193

211-
template <typename Base>
212-
StorageLocation *
213-
CachedConstAccessorsLattice<Base>::getOrCreateConstMethodReturnStorageLocation(
214-
const RecordStorageLocation &RecordLoc, const CallExpr *CE,
215-
Environment &Env, llvm::function_ref<void(StorageLocation &)> Initialize) {
216-
assert(!CE->getType().isNull());
217-
assert(CE->isGLValue() || CE->getType()->isRecordType());
218-
auto &ObjMap = ConstMethodReturnStorageLocations[&RecordLoc];
219-
const FunctionDecl *DirectCallee = CE->getDirectCallee();
220-
if (DirectCallee == nullptr)
221-
return nullptr;
222-
auto it = ObjMap.find(DirectCallee);
223-
if (it != ObjMap.end())
224-
return it->second;
225-
226-
StorageLocation &Loc =
227-
Env.createStorageLocation(CE->getType().getNonReferenceType());
228-
Initialize(Loc);
229-
230-
ObjMap.insert({DirectCallee, &Loc});
231-
return &Loc;
232-
}
233-
234194
template <typename Base>
235195
StorageLocation &
236196
CachedConstAccessorsLattice<Base>::getOrCreateConstMethodReturnStorageLocation(

clang/unittests/Analysis/FlowSensitive/CachedConstAccessorsLatticeTest.cpp

Lines changed: 18 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -128,33 +128,6 @@ TEST_F(CachedConstAccessorsLatticeTest, SameLocBeforeClearOrDiffAfterClear) {
128128
RecordStorageLocation Loc(Inputs.SType, RecordStorageLocation::FieldToLoc(),
129129
{});
130130

131-
LatticeT Lattice;
132-
auto NopInit = [](StorageLocation &) {};
133-
StorageLocation *Loc1 = Lattice.getOrCreateConstMethodReturnStorageLocation(
134-
Loc, CE, Env, NopInit);
135-
auto NotCalled = [](StorageLocation &) {
136-
ASSERT_TRUE(false) << "Not reached";
137-
};
138-
StorageLocation *Loc2 = Lattice.getOrCreateConstMethodReturnStorageLocation(
139-
Loc, CE, Env, NotCalled);
140-
141-
EXPECT_EQ(Loc1, Loc2);
142-
143-
Lattice.clearConstMethodReturnStorageLocations(Loc);
144-
StorageLocation *Loc3 = Lattice.getOrCreateConstMethodReturnStorageLocation(
145-
Loc, CE, Env, NopInit);
146-
147-
EXPECT_NE(Loc3, Loc1);
148-
EXPECT_NE(Loc3, Loc2);
149-
}
150-
151-
TEST_F(CachedConstAccessorsLatticeTest,
152-
SameLocBeforeClearOrDiffAfterClearWithCallee) {
153-
CommonTestInputs Inputs;
154-
auto *CE = Inputs.CallRef;
155-
RecordStorageLocation Loc(Inputs.SType, RecordStorageLocation::FieldToLoc(),
156-
{});
157-
158131
LatticeT Lattice;
159132
auto NopInit = [](StorageLocation &) {};
160133
const FunctionDecl *Callee = CE->getDirectCallee();
@@ -204,22 +177,24 @@ TEST_F(CachedConstAccessorsLatticeTest,
204177
// Accessors that return a record by value are modeled by a record storage
205178
// location (instead of a Value).
206179
auto NopInit = [](StorageLocation &) {};
207-
StorageLocation *Loc1 = Lattice.getOrCreateConstMethodReturnStorageLocation(
208-
Loc, CE, Env, NopInit);
180+
const FunctionDecl *Callee = CE->getDirectCallee();
181+
ASSERT_NE(Callee, nullptr);
182+
StorageLocation &Loc1 = Lattice.getOrCreateConstMethodReturnStorageLocation(
183+
Loc, Callee, Env, NopInit);
209184
auto NotCalled = [](StorageLocation &) {
210185
ASSERT_TRUE(false) << "Not reached";
211186
};
212-
StorageLocation *Loc2 = Lattice.getOrCreateConstMethodReturnStorageLocation(
213-
Loc, CE, Env, NotCalled);
187+
StorageLocation &Loc2 = Lattice.getOrCreateConstMethodReturnStorageLocation(
188+
Loc, Callee, Env, NotCalled);
214189

215-
EXPECT_EQ(Loc1, Loc2);
190+
EXPECT_EQ(&Loc1, &Loc2);
216191

217192
Lattice.clearConstMethodReturnStorageLocations(Loc);
218-
StorageLocation *Loc3 = Lattice.getOrCreateConstMethodReturnStorageLocation(
219-
Loc, CE, Env, NopInit);
193+
StorageLocation &Loc3 = Lattice.getOrCreateConstMethodReturnStorageLocation(
194+
Loc, Callee, Env, NopInit);
220195

221-
EXPECT_NE(Loc3, Loc1);
222-
EXPECT_NE(Loc3, Loc1);
196+
EXPECT_NE(&Loc3, &Loc1);
197+
EXPECT_NE(&Loc3, &Loc1);
223198
}
224199

225200
TEST_F(CachedConstAccessorsLatticeTest, ClearDifferentLocs) {
@@ -232,18 +207,20 @@ TEST_F(CachedConstAccessorsLatticeTest, ClearDifferentLocs) {
232207

233208
LatticeT Lattice;
234209
auto NopInit = [](StorageLocation &) {};
235-
StorageLocation *RetLoc1 =
236-
Lattice.getOrCreateConstMethodReturnStorageLocation(LocS1, CE, Env,
210+
const FunctionDecl *Callee = CE->getDirectCallee();
211+
ASSERT_NE(Callee, nullptr);
212+
StorageLocation &RetLoc1 =
213+
Lattice.getOrCreateConstMethodReturnStorageLocation(LocS1, Callee, Env,
237214
NopInit);
238215
Lattice.clearConstMethodReturnStorageLocations(LocS2);
239216
auto NotCalled = [](StorageLocation &) {
240217
ASSERT_TRUE(false) << "Not reached";
241218
};
242-
StorageLocation *RetLoc2 =
243-
Lattice.getOrCreateConstMethodReturnStorageLocation(LocS1, CE, Env,
219+
StorageLocation &RetLoc2 =
220+
Lattice.getOrCreateConstMethodReturnStorageLocation(LocS1, Callee, Env,
244221
NotCalled);
245222

246-
EXPECT_EQ(RetLoc1, RetLoc2);
223+
EXPECT_EQ(&RetLoc1, &RetLoc2);
247224
}
248225

249226
TEST_F(CachedConstAccessorsLatticeTest, DifferentValsFromDifferentLocs) {

0 commit comments

Comments
 (0)