@@ -3577,6 +3577,144 @@ TEST_F(DIExpressionTest, Fold) {
3577
3577
EXPECT_EQ (E, ResExpr);
3578
3578
}
3579
3579
3580
+ TEST_F (DIExpressionTest, Append) {
3581
+ // Test appending a {dwarf::DW_OP_constu, <const>, DW_OP_plus} to a DW_OP_plus
3582
+ // expression
3583
+ SmallVector<uint64_t , 8 > Ops = {dwarf::DW_OP_LLVM_arg, 0 , dwarf::DW_OP_constu,
3584
+ 2 , dwarf::DW_OP_plus};
3585
+ auto *Expr = DIExpression::get (Context, Ops);
3586
+ SmallVector<uint64_t , 8 > AppendOps = {dwarf::DW_OP_constu, 3 ,
3587
+ dwarf::DW_OP_plus};
3588
+ auto *AppendExpr = DIExpression::append (Expr, AppendOps);
3589
+ SmallVector<uint64_t , 8 > OpsRes = {dwarf::DW_OP_LLVM_arg, 0 ,
3590
+ dwarf::DW_OP_plus_uconst, 5 };
3591
+ auto *ResExpr = DIExpression::get (Context, OpsRes);
3592
+ EXPECT_EQ (ResExpr, AppendExpr);
3593
+
3594
+ // Test appending a {dwarf::DW_OP_plus_uconst, <const>} to a DW_OP_plus
3595
+ // expression uint64_t PlusUConstOps[] = {dwarf::DW_OP_plus_uconst, 3};
3596
+ AppendOps.clear ();
3597
+ AppendOps.push_back (dwarf::DW_OP_plus_uconst);
3598
+ AppendOps.push_back (3 );
3599
+ AppendExpr = DIExpression::append (Expr, AppendOps);
3600
+ OpsRes.clear ();
3601
+ OpsRes.push_back (dwarf::DW_OP_LLVM_arg);
3602
+ OpsRes.push_back (0 );
3603
+ OpsRes.push_back (dwarf::DW_OP_plus_uconst);
3604
+ OpsRes.push_back (5 );
3605
+ ResExpr = DIExpression::get (Context, OpsRes);
3606
+ EXPECT_EQ (ResExpr, AppendExpr);
3607
+
3608
+ // Test appending a {dwarf::DW_OP_constu, 0, DW_OP_plus} to an expression
3609
+ AppendOps.clear ();
3610
+ AppendOps.push_back (dwarf::DW_OP_constu);
3611
+ AppendOps.push_back (0 );
3612
+ AppendOps.push_back (dwarf::DW_OP_plus);
3613
+ AppendExpr = DIExpression::append (Expr, AppendOps);
3614
+ OpsRes.clear ();
3615
+ OpsRes.push_back (dwarf::DW_OP_LLVM_arg);
3616
+ OpsRes.push_back (0 );
3617
+ OpsRes.push_back (dwarf::DW_OP_plus_uconst);
3618
+ OpsRes.push_back (2 );
3619
+ ResExpr = DIExpression::get (Context, OpsRes);
3620
+ EXPECT_EQ (ResExpr, AppendExpr);
3621
+
3622
+ // Test appending a {dwarf::DW_OP_constu, 0, DW_OP_minus} to an expression
3623
+ AppendOps.clear ();
3624
+ AppendOps.push_back (dwarf::DW_OP_constu);
3625
+ AppendOps.push_back (0 );
3626
+ AppendOps.push_back (dwarf::DW_OP_minus);
3627
+ AppendExpr = DIExpression::append (Expr, AppendOps);
3628
+ OpsRes.clear ();
3629
+ OpsRes.push_back (dwarf::DW_OP_LLVM_arg);
3630
+ OpsRes.push_back (0 );
3631
+ OpsRes.push_back (dwarf::DW_OP_plus_uconst);
3632
+ OpsRes.push_back (2 );
3633
+ ResExpr = DIExpression::get (Context, OpsRes);
3634
+ EXPECT_EQ (ResExpr, AppendExpr);
3635
+
3636
+ // Test appending a {dwarf::DW_OP_constu, 0, DW_OP_shl} to an expression
3637
+ AppendOps.clear ();
3638
+ AppendOps.push_back (dwarf::DW_OP_constu);
3639
+ AppendOps.push_back (0 );
3640
+ AppendOps.push_back (dwarf::DW_OP_shl);
3641
+ AppendExpr = DIExpression::append (Expr, AppendOps);
3642
+ OpsRes.clear ();
3643
+ OpsRes.push_back (dwarf::DW_OP_LLVM_arg);
3644
+ OpsRes.push_back (0 );
3645
+ OpsRes.push_back (dwarf::DW_OP_plus_uconst);
3646
+ OpsRes.push_back (2 );
3647
+ ResExpr = DIExpression::get (Context, OpsRes);
3648
+ EXPECT_EQ (ResExpr, AppendExpr);
3649
+
3650
+ // Test appending a {dwarf::DW_OP_constu, 0, DW_OP_shr} to an expression
3651
+ AppendOps.clear ();
3652
+ AppendOps.push_back (dwarf::DW_OP_constu);
3653
+ AppendOps.push_back (0 );
3654
+ AppendOps.push_back (dwarf::DW_OP_shr);
3655
+ AppendExpr = DIExpression::append (Expr, AppendOps);
3656
+ OpsRes.clear ();
3657
+ OpsRes.push_back (dwarf::DW_OP_LLVM_arg);
3658
+ OpsRes.push_back (0 );
3659
+ OpsRes.push_back (dwarf::DW_OP_plus_uconst);
3660
+ OpsRes.push_back (2 );
3661
+ ResExpr = DIExpression::get (Context, OpsRes);
3662
+ EXPECT_EQ (ResExpr, AppendExpr);
3663
+
3664
+ // Test appending a {dwarf::DW_OP_constu, <const>, DW_OP_mul} to a DW_OP_mul
3665
+ // expression
3666
+ Ops.clear ();
3667
+ Ops.push_back (dwarf::DW_OP_LLVM_arg);
3668
+ Ops.push_back (0 );
3669
+ Ops.push_back (dwarf::DW_OP_constu);
3670
+ Ops.push_back (2 );
3671
+ Ops.push_back (dwarf::DW_OP_mul);
3672
+ Expr = DIExpression::get (Context, Ops);
3673
+ AppendOps.clear ();
3674
+ AppendOps.push_back (dwarf::DW_OP_constu);
3675
+ AppendOps.push_back (3 );
3676
+ AppendOps.push_back (dwarf::DW_OP_mul);
3677
+ AppendExpr = DIExpression::append (Expr, AppendOps);
3678
+ OpsRes.clear ();
3679
+ OpsRes.push_back (dwarf::DW_OP_LLVM_arg);
3680
+ OpsRes.push_back (0 );
3681
+ OpsRes.push_back (dwarf::DW_OP_constu);
3682
+ OpsRes.push_back (6 );
3683
+ OpsRes.push_back (dwarf::DW_OP_mul);
3684
+ ResExpr = DIExpression::get (Context, OpsRes);
3685
+ EXPECT_EQ (ResExpr, AppendExpr);
3686
+
3687
+ // Test appending a {dwarf::DW_OP_constu, 1, DW_OP_mul} to an expression
3688
+ AppendOps.clear ();
3689
+ AppendOps.push_back (dwarf::DW_OP_constu);
3690
+ AppendOps.push_back (1 );
3691
+ AppendOps.push_back (dwarf::DW_OP_mul);
3692
+ AppendExpr = DIExpression::append (Expr, AppendOps);
3693
+ OpsRes.clear ();
3694
+ OpsRes.push_back (dwarf::DW_OP_LLVM_arg);
3695
+ OpsRes.push_back (0 );
3696
+ OpsRes.push_back (dwarf::DW_OP_constu);
3697
+ OpsRes.push_back (2 );
3698
+ OpsRes.push_back (dwarf::DW_OP_mul);
3699
+ ResExpr = DIExpression::get (Context, OpsRes);
3700
+ EXPECT_EQ (ResExpr, AppendExpr);
3701
+
3702
+ // Test appending a {dwarf::DW_OP_constu, 1, DW_OP_div} to an expression
3703
+ AppendOps.clear ();
3704
+ AppendOps.push_back (dwarf::DW_OP_constu);
3705
+ AppendOps.push_back (1 );
3706
+ AppendOps.push_back (dwarf::DW_OP_div);
3707
+ AppendExpr = DIExpression::append (Expr, AppendOps);
3708
+ OpsRes.clear ();
3709
+ OpsRes.push_back (dwarf::DW_OP_LLVM_arg);
3710
+ OpsRes.push_back (0 );
3711
+ OpsRes.push_back (dwarf::DW_OP_constu);
3712
+ OpsRes.push_back (2 );
3713
+ OpsRes.push_back (dwarf::DW_OP_mul);
3714
+ ResExpr = DIExpression::get (Context, OpsRes);
3715
+ EXPECT_EQ (ResExpr, AppendExpr);
3716
+ }
3717
+
3580
3718
TEST_F (DIExpressionTest, isValid) {
3581
3719
#define EXPECT_VALID (...) \
3582
3720
do { \
0 commit comments