Skip to content

Commit 1e9b4fc

Browse files
committed
[clang][dataflow] Various refactorings in TypeErasedDataflowAnalysisTest.cpp
These simplify the code in their own right, but they are also useful in that they minimize the number of changes that will need to be made when then API of `AggregateStorageLocation` and `StructValue` changes as part of the migration to strict handling of value categories (see https://discourse.llvm.org/t/70086). Depends On D154949 Reviewed By: xazax.hun, gribozavr2 Differential Revision: https://reviews.llvm.org/D154952
1 parent 103a0fc commit 1e9b4fc

File tree

1 file changed

+20
-22
lines changed

1 file changed

+20
-22
lines changed

clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,13 @@ TEST_F(NoreturnDestructorTest, ConditionalOperatorNestedBranchReturns) {
370370
// FIXME: Called functions at point `p` should contain only "foo".
371371
}
372372

373+
StructValue &createNewStructValue(AggregateStorageLocation &Loc,
374+
Environment &Env) {
375+
auto &Val = *cast<StructValue>(Env.createValue(Loc.getType()));
376+
Env.setValue(Loc, Val);
377+
return Val;
378+
}
379+
373380
// Models an analysis that uses flow conditions.
374381
class SpecialBoolAnalysis final
375382
: public DataflowAnalysis<SpecialBoolAnalysis, NoopLattice> {
@@ -390,23 +397,18 @@ class SpecialBoolAnalysis final
390397
if (const auto *E = selectFirst<CXXConstructExpr>(
391398
"call", match(cxxConstructExpr(HasSpecialBoolType).bind("call"), *S,
392399
getASTContext()))) {
393-
auto &ConstructorVal = *Env.createValue(E->getType());
394-
ConstructorVal.setProperty("is_set", Env.getBoolLiteralValue(false));
395-
Env.setValue(*Env.getStorageLocation(*E, SkipPast::None), ConstructorVal);
400+
cast<StructValue>(Env.getValueStrict(*E))
401+
->setProperty("is_set", Env.getBoolLiteralValue(false));
396402
} else if (const auto *E = selectFirst<CXXMemberCallExpr>(
397403
"call", match(cxxMemberCallExpr(callee(cxxMethodDecl(ofClass(
398404
SpecialBoolRecordDecl))))
399405
.bind("call"),
400406
*S, getASTContext()))) {
401-
auto *Object = E->getImplicitObjectArgument();
402-
assert(Object != nullptr);
403-
404-
auto *ObjectLoc = getImplicitObjectLocation(*E, Env);
405-
assert(ObjectLoc != nullptr);
407+
auto &ObjectLoc =
408+
*cast<AggregateStorageLocation>(getImplicitObjectLocation(*E, Env));
406409

407-
auto &ConstructorVal = *Env.createValue(Object->getType());
408-
ConstructorVal.setProperty("is_set", Env.getBoolLiteralValue(true));
409-
Env.setValue(*ObjectLoc, ConstructorVal);
410+
createNewStructValue(ObjectLoc, Env)
411+
.setProperty("is_set", Env.getBoolLiteralValue(true));
410412
}
411413
}
412414

@@ -551,21 +553,19 @@ class OptionalIntAnalysis final
551553
*S, getASTContext());
552554
if (const auto *E = selectFirst<CXXConstructExpr>(
553555
"construct", Matches)) {
554-
auto &ConstructorVal = *Env.createValue(E->getType());
555-
ConstructorVal.setProperty("has_value", Env.getBoolLiteralValue(false));
556-
Env.setValue(*Env.getStorageLocation(*E, SkipPast::None), ConstructorVal);
556+
cast<StructValue>(Env.getValueStrict(*E))
557+
->setProperty("has_value", Env.getBoolLiteralValue(false));
557558
} else if (const auto *E =
558559
selectFirst<CXXOperatorCallExpr>("operator", Matches)) {
559560
assert(E->getNumArgs() > 0);
560561
auto *Object = E->getArg(0);
561562
assert(Object != nullptr);
562563

563-
auto *ObjectLoc = Env.getStorageLocation(*Object, SkipPast::Reference);
564-
assert(ObjectLoc != nullptr);
564+
auto &ObjectLoc = *cast<AggregateStorageLocation>(
565+
Env.getStorageLocation(*Object, SkipPast::Reference));
565566

566-
auto &ConstructorVal = *Env.createValue(Object->getType());
567-
ConstructorVal.setProperty("has_value", Env.getBoolLiteralValue(true));
568-
Env.setValue(*ObjectLoc, ConstructorVal);
567+
createNewStructValue(ObjectLoc, Env)
568+
.setProperty("has_value", Env.getBoolLiteralValue(true));
569569
}
570570
}
571571

@@ -1227,9 +1227,7 @@ class TopAnalysis final : public DataflowAnalysis<TopAnalysis, NoopLattice> {
12271227
match(callExpr(callee(functionDecl(hasName("makeTop")))).bind("top"),
12281228
*S, getASTContext());
12291229
if (const auto *E = selectFirst<CallExpr>("top", Matches)) {
1230-
auto &Loc = Env.createStorageLocation(*E);
1231-
Env.setValue(Loc, Env.makeTopBoolValue());
1232-
Env.setStorageLocation(*E, Loc);
1230+
Env.setValueStrict(*E, Env.makeTopBoolValue());
12331231
}
12341232
}
12351233

0 commit comments

Comments
 (0)