@@ -370,6 +370,13 @@ TEST_F(NoreturnDestructorTest, ConditionalOperatorNestedBranchReturns) {
370
370
// FIXME: Called functions at point `p` should contain only "foo".
371
371
}
372
372
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
+
373
380
// Models an analysis that uses flow conditions.
374
381
class SpecialBoolAnalysis final
375
382
: public DataflowAnalysis<SpecialBoolAnalysis, NoopLattice> {
@@ -390,23 +397,18 @@ class SpecialBoolAnalysis final
390
397
if (const auto *E = selectFirst<CXXConstructExpr>(
391
398
" call" , match (cxxConstructExpr (HasSpecialBoolType).bind (" call" ), *S,
392
399
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 ));
396
402
} else if (const auto *E = selectFirst<CXXMemberCallExpr>(
397
403
" call" , match (cxxMemberCallExpr (callee (cxxMethodDecl (ofClass (
398
404
SpecialBoolRecordDecl))))
399
405
.bind (" call" ),
400
406
*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));
406
409
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 ));
410
412
}
411
413
}
412
414
@@ -551,21 +553,19 @@ class OptionalIntAnalysis final
551
553
*S, getASTContext ());
552
554
if (const auto *E = selectFirst<CXXConstructExpr>(
553
555
" 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 ));
557
558
} else if (const auto *E =
558
559
selectFirst<CXXOperatorCallExpr>(" operator" , Matches)) {
559
560
assert (E->getNumArgs () > 0 );
560
561
auto *Object = E->getArg (0 );
561
562
assert (Object != nullptr );
562
563
563
- auto * ObjectLoc = Env. getStorageLocation (*Object, SkipPast::Reference);
564
- assert (ObjectLoc != nullptr );
564
+ auto & ObjectLoc = *cast<AggregateStorageLocation>(
565
+ Env. getStorageLocation (*Object, SkipPast::Reference) );
565
566
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 ));
569
569
}
570
570
}
571
571
@@ -1227,9 +1227,7 @@ class TopAnalysis final : public DataflowAnalysis<TopAnalysis, NoopLattice> {
1227
1227
match (callExpr (callee (functionDecl (hasName (" makeTop" )))).bind (" top" ),
1228
1228
*S, getASTContext ());
1229
1229
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 ());
1233
1231
}
1234
1232
}
1235
1233
0 commit comments