@@ -3639,6 +3639,144 @@ TEST_F(DIExpressionTest, Fold) {
3639
3639
EXPECT_EQ (E, ResExpr);
3640
3640
}
3641
3641
3642
+ TEST_F (DIExpressionTest, Append) {
3643
+ // Test appending a {dwarf::DW_OP_constu, <const>, DW_OP_plus} to a DW_OP_plus
3644
+ // expression
3645
+ SmallVector<uint64_t , 8 > Ops = {dwarf::DW_OP_LLVM_arg, 0 , dwarf::DW_OP_constu,
3646
+ 2 , dwarf::DW_OP_plus};
3647
+ auto *Expr = DIExpression::get (Context, Ops);
3648
+ SmallVector<uint64_t , 8 > AppendOps = {dwarf::DW_OP_constu, 3 ,
3649
+ dwarf::DW_OP_plus};
3650
+ auto *AppendExpr = DIExpression::append (Expr, AppendOps);
3651
+ SmallVector<uint64_t , 8 > OpsRes = {dwarf::DW_OP_LLVM_arg, 0 ,
3652
+ dwarf::DW_OP_plus_uconst, 5 };
3653
+ auto *ResExpr = DIExpression::get (Context, OpsRes);
3654
+ EXPECT_EQ (ResExpr, AppendExpr);
3655
+
3656
+ // Test appending a {dwarf::DW_OP_plus_uconst, <const>} to a DW_OP_plus
3657
+ // expression uint64_t PlusUConstOps[] = {dwarf::DW_OP_plus_uconst, 3};
3658
+ AppendOps.clear ();
3659
+ AppendOps.push_back (dwarf::DW_OP_plus_uconst);
3660
+ AppendOps.push_back (3 );
3661
+ AppendExpr = DIExpression::append (Expr, AppendOps);
3662
+ OpsRes.clear ();
3663
+ OpsRes.push_back (dwarf::DW_OP_LLVM_arg);
3664
+ OpsRes.push_back (0 );
3665
+ OpsRes.push_back (dwarf::DW_OP_plus_uconst);
3666
+ OpsRes.push_back (5 );
3667
+ ResExpr = DIExpression::get (Context, OpsRes);
3668
+ EXPECT_EQ (ResExpr, AppendExpr);
3669
+
3670
+ // Test appending a {dwarf::DW_OP_constu, 0, DW_OP_plus} to an expression
3671
+ AppendOps.clear ();
3672
+ AppendOps.push_back (dwarf::DW_OP_constu);
3673
+ AppendOps.push_back (0 );
3674
+ AppendOps.push_back (dwarf::DW_OP_plus);
3675
+ AppendExpr = DIExpression::append (Expr, AppendOps);
3676
+ OpsRes.clear ();
3677
+ OpsRes.push_back (dwarf::DW_OP_LLVM_arg);
3678
+ OpsRes.push_back (0 );
3679
+ OpsRes.push_back (dwarf::DW_OP_plus_uconst);
3680
+ OpsRes.push_back (2 );
3681
+ ResExpr = DIExpression::get (Context, OpsRes);
3682
+ EXPECT_EQ (ResExpr, AppendExpr);
3683
+
3684
+ // Test appending a {dwarf::DW_OP_constu, 0, DW_OP_minus} to an expression
3685
+ AppendOps.clear ();
3686
+ AppendOps.push_back (dwarf::DW_OP_constu);
3687
+ AppendOps.push_back (0 );
3688
+ AppendOps.push_back (dwarf::DW_OP_minus);
3689
+ AppendExpr = DIExpression::append (Expr, AppendOps);
3690
+ OpsRes.clear ();
3691
+ OpsRes.push_back (dwarf::DW_OP_LLVM_arg);
3692
+ OpsRes.push_back (0 );
3693
+ OpsRes.push_back (dwarf::DW_OP_plus_uconst);
3694
+ OpsRes.push_back (2 );
3695
+ ResExpr = DIExpression::get (Context, OpsRes);
3696
+ EXPECT_EQ (ResExpr, AppendExpr);
3697
+
3698
+ // Test appending a {dwarf::DW_OP_constu, 0, DW_OP_shl} to an expression
3699
+ AppendOps.clear ();
3700
+ AppendOps.push_back (dwarf::DW_OP_constu);
3701
+ AppendOps.push_back (0 );
3702
+ AppendOps.push_back (dwarf::DW_OP_shl);
3703
+ AppendExpr = DIExpression::append (Expr, AppendOps);
3704
+ OpsRes.clear ();
3705
+ OpsRes.push_back (dwarf::DW_OP_LLVM_arg);
3706
+ OpsRes.push_back (0 );
3707
+ OpsRes.push_back (dwarf::DW_OP_plus_uconst);
3708
+ OpsRes.push_back (2 );
3709
+ ResExpr = DIExpression::get (Context, OpsRes);
3710
+ EXPECT_EQ (ResExpr, AppendExpr);
3711
+
3712
+ // Test appending a {dwarf::DW_OP_constu, 0, DW_OP_shr} to an expression
3713
+ AppendOps.clear ();
3714
+ AppendOps.push_back (dwarf::DW_OP_constu);
3715
+ AppendOps.push_back (0 );
3716
+ AppendOps.push_back (dwarf::DW_OP_shr);
3717
+ AppendExpr = DIExpression::append (Expr, AppendOps);
3718
+ OpsRes.clear ();
3719
+ OpsRes.push_back (dwarf::DW_OP_LLVM_arg);
3720
+ OpsRes.push_back (0 );
3721
+ OpsRes.push_back (dwarf::DW_OP_plus_uconst);
3722
+ OpsRes.push_back (2 );
3723
+ ResExpr = DIExpression::get (Context, OpsRes);
3724
+ EXPECT_EQ (ResExpr, AppendExpr);
3725
+
3726
+ // Test appending a {dwarf::DW_OP_constu, <const>, DW_OP_mul} to a DW_OP_mul
3727
+ // expression
3728
+ Ops.clear ();
3729
+ Ops.push_back (dwarf::DW_OP_LLVM_arg);
3730
+ Ops.push_back (0 );
3731
+ Ops.push_back (dwarf::DW_OP_constu);
3732
+ Ops.push_back (2 );
3733
+ Ops.push_back (dwarf::DW_OP_mul);
3734
+ Expr = DIExpression::get (Context, Ops);
3735
+ AppendOps.clear ();
3736
+ AppendOps.push_back (dwarf::DW_OP_constu);
3737
+ AppendOps.push_back (3 );
3738
+ AppendOps.push_back (dwarf::DW_OP_mul);
3739
+ AppendExpr = DIExpression::append (Expr, AppendOps);
3740
+ OpsRes.clear ();
3741
+ OpsRes.push_back (dwarf::DW_OP_LLVM_arg);
3742
+ OpsRes.push_back (0 );
3743
+ OpsRes.push_back (dwarf::DW_OP_constu);
3744
+ OpsRes.push_back (6 );
3745
+ OpsRes.push_back (dwarf::DW_OP_mul);
3746
+ ResExpr = DIExpression::get (Context, OpsRes);
3747
+ EXPECT_EQ (ResExpr, AppendExpr);
3748
+
3749
+ // Test appending a {dwarf::DW_OP_constu, 1, DW_OP_mul} to an expression
3750
+ AppendOps.clear ();
3751
+ AppendOps.push_back (dwarf::DW_OP_constu);
3752
+ AppendOps.push_back (1 );
3753
+ AppendOps.push_back (dwarf::DW_OP_mul);
3754
+ AppendExpr = DIExpression::append (Expr, AppendOps);
3755
+ OpsRes.clear ();
3756
+ OpsRes.push_back (dwarf::DW_OP_LLVM_arg);
3757
+ OpsRes.push_back (0 );
3758
+ OpsRes.push_back (dwarf::DW_OP_constu);
3759
+ OpsRes.push_back (2 );
3760
+ OpsRes.push_back (dwarf::DW_OP_mul);
3761
+ ResExpr = DIExpression::get (Context, OpsRes);
3762
+ EXPECT_EQ (ResExpr, AppendExpr);
3763
+
3764
+ // Test appending a {dwarf::DW_OP_constu, 1, DW_OP_div} to an expression
3765
+ AppendOps.clear ();
3766
+ AppendOps.push_back (dwarf::DW_OP_constu);
3767
+ AppendOps.push_back (1 );
3768
+ AppendOps.push_back (dwarf::DW_OP_div);
3769
+ AppendExpr = DIExpression::append (Expr, AppendOps);
3770
+ OpsRes.clear ();
3771
+ OpsRes.push_back (dwarf::DW_OP_LLVM_arg);
3772
+ OpsRes.push_back (0 );
3773
+ OpsRes.push_back (dwarf::DW_OP_constu);
3774
+ OpsRes.push_back (2 );
3775
+ OpsRes.push_back (dwarf::DW_OP_mul);
3776
+ ResExpr = DIExpression::get (Context, OpsRes);
3777
+ EXPECT_EQ (ResExpr, AppendExpr);
3778
+ }
3779
+
3642
3780
TEST_F (DIExpressionTest, isValid) {
3643
3781
#define EXPECT_VALID (...) \
3644
3782
do { \
0 commit comments