Skip to content

Commit 3676abd

Browse files
Use DIExpression:foldConstantMath() at the result of an append()
1 parent 056a04d commit 3676abd

File tree

4 files changed

+93
-4
lines changed

4 files changed

+93
-4
lines changed

llvm/lib/IR/DebugInfoMetadata.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1871,7 +1871,8 @@ DIExpression *DIExpression::append(const DIExpression *Expr,
18711871
Op.appendToVector(NewOps);
18721872
}
18731873
NewOps.append(Ops.begin(), Ops.end());
1874-
auto *result = DIExpression::get(Expr->getContext(), NewOps);
1874+
auto *result =
1875+
DIExpression::get(Expr->getContext(), NewOps)->foldConstantMath();
18751876
assert(result->isValid() && "concatenated expression is not valid");
18761877
return result;
18771878
}

llvm/test/Bitcode/upgrade-dbg-addr.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ entry:
88
%num.addr = alloca i32, align 4
99
store i32 %num, ptr %num.addr, align 4
1010
; CHECK-NOT: call void @llvm.dbg.addr
11-
; CHECK: call void @llvm.dbg.value(metadata ptr %num.addr, metadata ![[#]], metadata !DIExpression(DW_OP_plus_uconst, 0, DW_OP_deref))
11+
; CHECK: call void @llvm.dbg.value(metadata ptr %num.addr, metadata ![[#]], metadata !DIExpression(DW_OP_deref))
1212
call void @llvm.dbg.addr(metadata ptr %num.addr, metadata !16, metadata !DIExpression(DW_OP_plus_uconst, 0)), !dbg !17
1313
%0 = load i32, ptr %num.addr, align 4
1414
ret i32 %0

llvm/test/DebugInfo/MIR/AArch64/dbgcall-site-expr-chain.mir

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,12 @@ body: |
105105

106106
# CHECK: DW_TAG_GNU_call_site_parameter
107107
# CHECK-NEXT: DW_AT_location (DW_OP_reg2 W2)
108-
# CHECK-NEXT: DW_AT_GNU_call_site_value (DW_OP_breg19 W19+700, DW_OP_plus_uconst 0x9, DW_OP_plus_uconst 0x50)
108+
# CHECK-NEXT: DW_AT_GNU_call_site_value (DW_OP_breg19 W19+789)
109109

110110
# CHECK: DW_TAG_GNU_call_site_parameter
111111
# CHECK-NEXT: DW_AT_location (DW_OP_reg1 W1)
112112
# CHECK-NEXT: DW_AT_GNU_call_site_value (DW_OP_breg19 W19-406, DW_OP_constu 0x32, DW_OP_minus)
113113

114114
# CHECK: DW_TAG_GNU_call_site_parameter
115115
# CHECK-NEXT: DW_AT_location (DW_OP_reg0 W0)
116-
# CHECK-NEXT: DW_AT_GNU_call_site_value (DW_OP_breg19 W19+100, DW_OP_plus_uconst 0x17)
116+
# CHECK-NEXT: DW_AT_GNU_call_site_value (DW_OP_breg19 W19+123)

llvm/unittests/IR/MetadataTest.cpp

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3577,6 +3577,94 @@ TEST_F(DIExpressionTest, Fold) {
35773577
EXPECT_EQ(E, ResExpr);
35783578
}
35793579

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[0] = dwarf::DW_OP_constu;
3610+
AppendOps[1] = 0;
3611+
AppendOps.push_back(dwarf::DW_OP_plus);
3612+
AppendExpr = DIExpression::append(Expr, AppendOps);
3613+
OpsRes[2] = dwarf::DW_OP_plus_uconst;
3614+
OpsRes[3] = Ops[3];
3615+
ResExpr = DIExpression::get(Context, OpsRes);
3616+
EXPECT_EQ(ResExpr, AppendExpr);
3617+
3618+
// Test appending a {dwarf::DW_OP_constu, 0, DW_OP_minus} to an expression
3619+
AppendOps[2] = dwarf::DW_OP_minus;
3620+
AppendExpr = DIExpression::append(Expr, AppendOps);
3621+
OpsRes[3] = Ops[3];
3622+
ResExpr = DIExpression::get(Context, OpsRes);
3623+
EXPECT_EQ(ResExpr, AppendExpr);
3624+
3625+
// Test appending a {dwarf::DW_OP_constu, 0, DW_OP_shl} to an expression
3626+
AppendOps[2] = dwarf::DW_OP_shl;
3627+
AppendExpr = DIExpression::append(Expr, AppendOps);
3628+
OpsRes[3] = Ops[3];
3629+
ResExpr = DIExpression::get(Context, OpsRes);
3630+
EXPECT_EQ(ResExpr, AppendExpr);
3631+
3632+
// Test appending a {dwarf::DW_OP_constu, 0, DW_OP_shr} to an expression
3633+
AppendOps[2] = dwarf::DW_OP_shr;
3634+
AppendExpr = DIExpression::append(Expr, AppendOps);
3635+
OpsRes[3] = Ops[3];
3636+
ResExpr = DIExpression::get(Context, OpsRes);
3637+
EXPECT_EQ(ResExpr, AppendExpr);
3638+
3639+
// Test appending a {dwarf::DW_OP_constu, <const>, DW_OP_mul} to a DW_OP_mul
3640+
// expression
3641+
Ops[4] = dwarf::DW_OP_mul;
3642+
Expr = DIExpression::get(Context, Ops);
3643+
AppendOps[1] = 3;
3644+
AppendOps[2] = dwarf::DW_OP_mul;
3645+
AppendExpr = DIExpression::append(Expr, AppendOps);
3646+
OpsRes[2] = dwarf::DW_OP_constu;
3647+
OpsRes[3] = 6;
3648+
OpsRes.push_back(dwarf::DW_OP_mul);
3649+
ResExpr = DIExpression::get(Context, OpsRes);
3650+
EXPECT_EQ(ResExpr, AppendExpr);
3651+
3652+
// Test appending a {dwarf::DW_OP_constu, 1, DW_OP_mul} to an expression
3653+
AppendOps[1] = 1;
3654+
AppendExpr = DIExpression::append(Expr, AppendOps);
3655+
OpsRes[3] = Ops[3];
3656+
ResExpr = DIExpression::get(Context, OpsRes);
3657+
EXPECT_EQ(ResExpr, AppendExpr);
3658+
3659+
// Test appending a {dwarf::DW_OP_constu, 1, DW_OP_div} to an expression
3660+
AppendOps[1] = 1;
3661+
AppendOps[2] = dwarf::DW_OP_div;
3662+
AppendExpr = DIExpression::append(Expr, AppendOps);
3663+
OpsRes[3] = Ops[3];
3664+
ResExpr = DIExpression::get(Context, OpsRes);
3665+
EXPECT_EQ(ResExpr, AppendExpr);
3666+
}
3667+
35803668
TEST_F(DIExpressionTest, isValid) {
35813669
#define EXPECT_VALID(...) \
35823670
do { \

0 commit comments

Comments
 (0)