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