@@ -3370,20 +3370,11 @@ TEST(TransferTest, IntegralCast) {
3370
3370
Code,
3371
3371
[](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
3372
3372
ASTContext &ASTCtx) {
3373
- ASSERT_THAT (Results.keys (), UnorderedElementsAre (" p" ));
3374
3373
const Environment &Env = getEnvironmentAtAnnotation (Results, " p" );
3375
3374
3376
- const ValueDecl *FooDecl = findValueDecl (ASTCtx, " Foo" );
3377
- ASSERT_THAT (FooDecl, NotNull ());
3378
-
3379
- const ValueDecl *BarDecl = findValueDecl (ASTCtx, " Bar" );
3380
- ASSERT_THAT (BarDecl, NotNull ());
3381
-
3382
- const auto *FooVal = Env.getValue (*FooDecl);
3383
- const auto *BarVal = Env.getValue (*BarDecl);
3384
- EXPECT_TRUE (isa<IntegerValue>(FooVal));
3385
- EXPECT_TRUE (isa<IntegerValue>(BarVal));
3386
- EXPECT_EQ (FooVal, BarVal);
3375
+ const auto &FooVal = getValueForDecl<IntegerValue>(ASTCtx, Env, " Foo" );
3376
+ const auto &BarVal = getValueForDecl<IntegerValue>(ASTCtx, Env, " Bar" );
3377
+ EXPECT_EQ (&FooVal, &BarVal);
3387
3378
});
3388
3379
}
3389
3380
@@ -3398,17 +3389,10 @@ TEST(TransferTest, IntegraltoBooleanCast) {
3398
3389
Code,
3399
3390
[](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
3400
3391
ASTContext &ASTCtx) {
3401
- ASSERT_THAT (Results.keys (), UnorderedElementsAre (" p" ));
3402
3392
const Environment &Env = getEnvironmentAtAnnotation (Results, " p" );
3403
3393
3404
- const ValueDecl *FooDecl = findValueDecl (ASTCtx, " Foo" );
3405
- ASSERT_THAT (FooDecl, NotNull ());
3406
-
3407
- const ValueDecl *BarDecl = findValueDecl (ASTCtx, " Bar" );
3408
- ASSERT_THAT (BarDecl, NotNull ());
3409
-
3410
- const auto *FooVal = Env.getValue (*FooDecl);
3411
- const auto *BarVal = Env.getValue (*BarDecl);
3394
+ const auto &FooVal = getValueForDecl (ASTCtx, Env, " Foo" );
3395
+ const auto &BarVal = getValueForDecl (ASTCtx, Env, " Bar" );
3412
3396
EXPECT_TRUE (isa<IntegerValue>(FooVal));
3413
3397
EXPECT_TRUE (isa<BoolValue>(BarVal));
3414
3398
});
@@ -3426,23 +3410,38 @@ TEST(TransferTest, IntegralToBooleanCastFromBool) {
3426
3410
Code,
3427
3411
[](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &Results,
3428
3412
ASTContext &ASTCtx) {
3429
- ASSERT_THAT (Results.keys (), UnorderedElementsAre (" p" ));
3430
3413
const Environment &Env = getEnvironmentAtAnnotation (Results, " p" );
3431
3414
3432
- const ValueDecl *FooDecl = findValueDecl (ASTCtx, " Foo" );
3433
- ASSERT_THAT (FooDecl, NotNull ());
3434
-
3435
- const ValueDecl *BarDecl = findValueDecl (ASTCtx, " Bar" );
3436
- ASSERT_THAT (BarDecl, NotNull ());
3437
-
3438
- const auto *FooVal = Env.getValue (*FooDecl);
3439
- const auto *BarVal = Env.getValue (*BarDecl);
3440
- EXPECT_TRUE (isa<BoolValue>(FooVal));
3441
- EXPECT_TRUE (isa<BoolValue>(BarVal));
3442
- EXPECT_EQ (FooVal, BarVal);
3415
+ const auto &FooVal = getValueForDecl<BoolValue>(ASTCtx, Env, " Foo" );
3416
+ const auto &BarVal = getValueForDecl<BoolValue>(ASTCtx, Env, " Bar" );
3417
+ EXPECT_EQ (&FooVal, &BarVal);
3443
3418
});
3444
3419
}
3445
3420
3421
+ TEST (TransferTest, WidenBoolValueInIntegerVariable) {
3422
+ // This is a crash repro.
3423
+ // This test sets up a case where we perform widening on an integer variable
3424
+ // that contains a `BoolValue` for the previous iteration and an
3425
+ // `IntegerValue` for the current iteration. We used to crash on this because
3426
+ // `widenDistinctValues()` assumed that if the previous iteration had a
3427
+ // `BoolValue`, the current iteration would too.
3428
+ // FIXME: The real fix here is to make sure we never store `BoolValue`s in
3429
+ // integer variables; see also the comment in `widenDistinctValues()`.
3430
+ std::string Code = R"cc(
3431
+ struct S {
3432
+ int i;
3433
+ S *next;
3434
+ };
3435
+ void target(S *s) {
3436
+ for (; s; s = s->next)
3437
+ s->i = false;
3438
+ }
3439
+ )cc" ;
3440
+ runDataflow (Code,
3441
+ [](const llvm::StringMap<DataflowAnalysisState<NoopLattice>> &,
3442
+ ASTContext &) {});
3443
+ }
3444
+
3446
3445
TEST (TransferTest, NullToPointerCast) {
3447
3446
std::string Code = R"(
3448
3447
using my_nullptr_t = decltype(nullptr);
0 commit comments