@@ -3610,6 +3610,144 @@ TEST_F(DIExpressionTest, Fold) {
3610
3610
EXPECT_EQ (E, ResExpr);
3611
3611
}
3612
3612
3613
+ TEST_F (DIExpressionTest, Append) {
3614
+ // Test appending a {dwarf::DW_OP_constu, <const>, DW_OP_plus} to a DW_OP_plus
3615
+ // expression
3616
+ SmallVector<uint64_t , 8 > Ops = {dwarf::DW_OP_LLVM_arg, 0 , dwarf::DW_OP_constu,
3617
+ 2 , dwarf::DW_OP_plus};
3618
+ auto *Expr = DIExpression::get (Context, Ops);
3619
+ SmallVector<uint64_t , 8 > AppendOps = {dwarf::DW_OP_constu, 3 ,
3620
+ dwarf::DW_OP_plus};
3621
+ auto *AppendExpr = DIExpression::append (Expr, AppendOps);
3622
+ SmallVector<uint64_t , 8 > OpsRes = {dwarf::DW_OP_LLVM_arg, 0 ,
3623
+ dwarf::DW_OP_plus_uconst, 5 };
3624
+ auto *ResExpr = DIExpression::get (Context, OpsRes);
3625
+ EXPECT_EQ (ResExpr, AppendExpr);
3626
+
3627
+ // Test appending a {dwarf::DW_OP_plus_uconst, <const>} to a DW_OP_plus
3628
+ // expression uint64_t PlusUConstOps[] = {dwarf::DW_OP_plus_uconst, 3};
3629
+ AppendOps.clear ();
3630
+ AppendOps.push_back (dwarf::DW_OP_plus_uconst);
3631
+ AppendOps.push_back (3 );
3632
+ AppendExpr = DIExpression::append (Expr, AppendOps);
3633
+ OpsRes.clear ();
3634
+ OpsRes.push_back (dwarf::DW_OP_LLVM_arg);
3635
+ OpsRes.push_back (0 );
3636
+ OpsRes.push_back (dwarf::DW_OP_plus_uconst);
3637
+ OpsRes.push_back (5 );
3638
+ ResExpr = DIExpression::get (Context, OpsRes);
3639
+ EXPECT_EQ (ResExpr, AppendExpr);
3640
+
3641
+ // Test appending a {dwarf::DW_OP_constu, 0, DW_OP_plus} to an expression
3642
+ AppendOps.clear ();
3643
+ AppendOps.push_back (dwarf::DW_OP_constu);
3644
+ AppendOps.push_back (0 );
3645
+ AppendOps.push_back (dwarf::DW_OP_plus);
3646
+ AppendExpr = DIExpression::append (Expr, AppendOps);
3647
+ OpsRes.clear ();
3648
+ OpsRes.push_back (dwarf::DW_OP_LLVM_arg);
3649
+ OpsRes.push_back (0 );
3650
+ OpsRes.push_back (dwarf::DW_OP_plus_uconst);
3651
+ OpsRes.push_back (2 );
3652
+ ResExpr = DIExpression::get (Context, OpsRes);
3653
+ EXPECT_EQ (ResExpr, AppendExpr);
3654
+
3655
+ // Test appending a {dwarf::DW_OP_constu, 0, DW_OP_minus} to an expression
3656
+ AppendOps.clear ();
3657
+ AppendOps.push_back (dwarf::DW_OP_constu);
3658
+ AppendOps.push_back (0 );
3659
+ AppendOps.push_back (dwarf::DW_OP_minus);
3660
+ AppendExpr = DIExpression::append (Expr, AppendOps);
3661
+ OpsRes.clear ();
3662
+ OpsRes.push_back (dwarf::DW_OP_LLVM_arg);
3663
+ OpsRes.push_back (0 );
3664
+ OpsRes.push_back (dwarf::DW_OP_plus_uconst);
3665
+ OpsRes.push_back (2 );
3666
+ ResExpr = DIExpression::get (Context, OpsRes);
3667
+ EXPECT_EQ (ResExpr, AppendExpr);
3668
+
3669
+ // Test appending a {dwarf::DW_OP_constu, 0, DW_OP_shl} to an expression
3670
+ AppendOps.clear ();
3671
+ AppendOps.push_back (dwarf::DW_OP_constu);
3672
+ AppendOps.push_back (0 );
3673
+ AppendOps.push_back (dwarf::DW_OP_shl);
3674
+ AppendExpr = DIExpression::append (Expr, AppendOps);
3675
+ OpsRes.clear ();
3676
+ OpsRes.push_back (dwarf::DW_OP_LLVM_arg);
3677
+ OpsRes.push_back (0 );
3678
+ OpsRes.push_back (dwarf::DW_OP_plus_uconst);
3679
+ OpsRes.push_back (2 );
3680
+ ResExpr = DIExpression::get (Context, OpsRes);
3681
+ EXPECT_EQ (ResExpr, AppendExpr);
3682
+
3683
+ // Test appending a {dwarf::DW_OP_constu, 0, DW_OP_shr} to an expression
3684
+ AppendOps.clear ();
3685
+ AppendOps.push_back (dwarf::DW_OP_constu);
3686
+ AppendOps.push_back (0 );
3687
+ AppendOps.push_back (dwarf::DW_OP_shr);
3688
+ AppendExpr = DIExpression::append (Expr, AppendOps);
3689
+ OpsRes.clear ();
3690
+ OpsRes.push_back (dwarf::DW_OP_LLVM_arg);
3691
+ OpsRes.push_back (0 );
3692
+ OpsRes.push_back (dwarf::DW_OP_plus_uconst);
3693
+ OpsRes.push_back (2 );
3694
+ ResExpr = DIExpression::get (Context, OpsRes);
3695
+ EXPECT_EQ (ResExpr, AppendExpr);
3696
+
3697
+ // Test appending a {dwarf::DW_OP_constu, <const>, DW_OP_mul} to a DW_OP_mul
3698
+ // expression
3699
+ Ops.clear ();
3700
+ Ops.push_back (dwarf::DW_OP_LLVM_arg);
3701
+ Ops.push_back (0 );
3702
+ Ops.push_back (dwarf::DW_OP_constu);
3703
+ Ops.push_back (2 );
3704
+ Ops.push_back (dwarf::DW_OP_mul);
3705
+ Expr = DIExpression::get (Context, Ops);
3706
+ AppendOps.clear ();
3707
+ AppendOps.push_back (dwarf::DW_OP_constu);
3708
+ AppendOps.push_back (3 );
3709
+ AppendOps.push_back (dwarf::DW_OP_mul);
3710
+ AppendExpr = DIExpression::append (Expr, AppendOps);
3711
+ OpsRes.clear ();
3712
+ OpsRes.push_back (dwarf::DW_OP_LLVM_arg);
3713
+ OpsRes.push_back (0 );
3714
+ OpsRes.push_back (dwarf::DW_OP_constu);
3715
+ OpsRes.push_back (6 );
3716
+ OpsRes.push_back (dwarf::DW_OP_mul);
3717
+ ResExpr = DIExpression::get (Context, OpsRes);
3718
+ EXPECT_EQ (ResExpr, AppendExpr);
3719
+
3720
+ // Test appending a {dwarf::DW_OP_constu, 1, DW_OP_mul} to an expression
3721
+ AppendOps.clear ();
3722
+ AppendOps.push_back (dwarf::DW_OP_constu);
3723
+ AppendOps.push_back (1 );
3724
+ AppendOps.push_back (dwarf::DW_OP_mul);
3725
+ AppendExpr = DIExpression::append (Expr, AppendOps);
3726
+ OpsRes.clear ();
3727
+ OpsRes.push_back (dwarf::DW_OP_LLVM_arg);
3728
+ OpsRes.push_back (0 );
3729
+ OpsRes.push_back (dwarf::DW_OP_constu);
3730
+ OpsRes.push_back (2 );
3731
+ OpsRes.push_back (dwarf::DW_OP_mul);
3732
+ ResExpr = DIExpression::get (Context, OpsRes);
3733
+ EXPECT_EQ (ResExpr, AppendExpr);
3734
+
3735
+ // Test appending a {dwarf::DW_OP_constu, 1, DW_OP_div} to an expression
3736
+ AppendOps.clear ();
3737
+ AppendOps.push_back (dwarf::DW_OP_constu);
3738
+ AppendOps.push_back (1 );
3739
+ AppendOps.push_back (dwarf::DW_OP_div);
3740
+ AppendExpr = DIExpression::append (Expr, AppendOps);
3741
+ OpsRes.clear ();
3742
+ OpsRes.push_back (dwarf::DW_OP_LLVM_arg);
3743
+ OpsRes.push_back (0 );
3744
+ OpsRes.push_back (dwarf::DW_OP_constu);
3745
+ OpsRes.push_back (2 );
3746
+ OpsRes.push_back (dwarf::DW_OP_mul);
3747
+ ResExpr = DIExpression::get (Context, OpsRes);
3748
+ EXPECT_EQ (ResExpr, AppendExpr);
3749
+ }
3750
+
3613
3751
TEST_F (DIExpressionTest, isValid) {
3614
3752
#define EXPECT_VALID (...) \
3615
3753
do { \
0 commit comments