diff --git a/clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp b/clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp index 473750ad7a6cb..d811aed8fddd9 100644 --- a/clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp +++ b/clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp @@ -370,6 +370,13 @@ TEST_F(NoreturnDestructorTest, ConditionalOperatorNestedBranchReturns) { // FIXME: Called functions at point `p` should contain only "foo". } +StructValue &createNewStructValue(AggregateStorageLocation &Loc, + Environment &Env) { + auto &Val = *cast(Env.createValue(Loc.getType())); + Env.setValue(Loc, Val); + return Val; +} + // Models an analysis that uses flow conditions. class SpecialBoolAnalysis final : public DataflowAnalysis { @@ -390,23 +397,18 @@ class SpecialBoolAnalysis final if (const auto *E = selectFirst( "call", match(cxxConstructExpr(HasSpecialBoolType).bind("call"), *S, getASTContext()))) { - auto &ConstructorVal = *Env.createValue(E->getType()); - ConstructorVal.setProperty("is_set", Env.getBoolLiteralValue(false)); - Env.setValue(*Env.getStorageLocation(*E, SkipPast::None), ConstructorVal); + cast(Env.getValueStrict(*E)) + ->setProperty("is_set", Env.getBoolLiteralValue(false)); } else if (const auto *E = selectFirst( "call", match(cxxMemberCallExpr(callee(cxxMethodDecl(ofClass( SpecialBoolRecordDecl)))) .bind("call"), *S, getASTContext()))) { - auto *Object = E->getImplicitObjectArgument(); - assert(Object != nullptr); - - auto *ObjectLoc = getImplicitObjectLocation(*E, Env); - assert(ObjectLoc != nullptr); + auto &ObjectLoc = + *cast(getImplicitObjectLocation(*E, Env)); - auto &ConstructorVal = *Env.createValue(Object->getType()); - ConstructorVal.setProperty("is_set", Env.getBoolLiteralValue(true)); - Env.setValue(*ObjectLoc, ConstructorVal); + createNewStructValue(ObjectLoc, Env) + .setProperty("is_set", Env.getBoolLiteralValue(true)); } } @@ -551,21 +553,19 @@ class OptionalIntAnalysis final *S, getASTContext()); if (const auto *E = selectFirst( "construct", Matches)) { - auto &ConstructorVal = *Env.createValue(E->getType()); - ConstructorVal.setProperty("has_value", Env.getBoolLiteralValue(false)); - Env.setValue(*Env.getStorageLocation(*E, SkipPast::None), ConstructorVal); + cast(Env.getValueStrict(*E)) + ->setProperty("has_value", Env.getBoolLiteralValue(false)); } else if (const auto *E = selectFirst("operator", Matches)) { assert(E->getNumArgs() > 0); auto *Object = E->getArg(0); assert(Object != nullptr); - auto *ObjectLoc = Env.getStorageLocation(*Object, SkipPast::Reference); - assert(ObjectLoc != nullptr); + auto &ObjectLoc = *cast( + Env.getStorageLocation(*Object, SkipPast::Reference)); - auto &ConstructorVal = *Env.createValue(Object->getType()); - ConstructorVal.setProperty("has_value", Env.getBoolLiteralValue(true)); - Env.setValue(*ObjectLoc, ConstructorVal); + createNewStructValue(ObjectLoc, Env) + .setProperty("has_value", Env.getBoolLiteralValue(true)); } } @@ -1227,9 +1227,7 @@ class TopAnalysis final : public DataflowAnalysis { match(callExpr(callee(functionDecl(hasName("makeTop")))).bind("top"), *S, getASTContext()); if (const auto *E = selectFirst("top", Matches)) { - auto &Loc = Env.createStorageLocation(*E); - Env.setValue(Loc, Env.makeTopBoolValue()); - Env.setStorageLocation(*E, Loc); + Env.setValueStrict(*E, Env.makeTopBoolValue()); } }