[llvm] Use DIExpression::foldConstantMath() at the result of an append() (PR #71719)

Jeremy Morse via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 14 10:04:09 PST 2023


================
@@ -3397,6 +3397,92 @@ TEST_F(DIExpressionTest, Fold) {
   EXPECT_EQ(E, ResExpr);
 }
 
+TEST_F(DIExpressionTest, Append) {
+    // Test appending a {dwarf::DW_OP_constu, <const>, DW_OP_plus} to a DW_OP_plus expression
+    SmallVector<uint64_t, 8> Ops = {dwarf::DW_OP_LLVM_arg, 0,
+                                    dwarf::DW_OP_constu, 2, dwarf::DW_OP_plus};
+    auto *Expr = DIExpression::get(Context, Ops);
+    SmallVector<uint64_t, 8> AppendOps = {dwarf::DW_OP_constu, 3,
+                                          dwarf::DW_OP_plus};
+    auto *AppendExpr = DIExpression::append(Expr, AppendOps);
+    SmallVector<uint64_t, 8> OpsRes = {
+        dwarf::DW_OP_LLVM_arg, 0, dwarf::DW_OP_constu, 5, dwarf::DW_OP_plus};
+    auto *ResExpr = DIExpression::get(Context, OpsRes);
+    EXPECT_EQ(ResExpr, AppendExpr);
+
+    // Test appending a {dwarf::DW_OP_plus_uconst, <const>} to a DW_OP_plus
+    // expression uint64_t PlusUConstOps[] = {dwarf::DW_OP_plus_uconst, 3};
+    AppendOps.clear();
+    AppendOps.push_back(dwarf::DW_OP_plus_uconst);
+    AppendOps.push_back(3);
+    AppendExpr = DIExpression::append(Expr, AppendOps);
+    OpsRes.clear();
+    OpsRes.push_back(dwarf::DW_OP_LLVM_arg);
+    OpsRes.push_back(0);
+    OpsRes.push_back(dwarf::DW_OP_plus_uconst);
+    OpsRes.push_back(5);
+    ResExpr = DIExpression::get(Context, OpsRes);
+    EXPECT_EQ(ResExpr, AppendExpr);
+
+    // Test appending a {dwarf::DW_OP_constu, 0, DW_OP_plus} to an expression
+    AppendOps[0] = dwarf::DW_OP_constu;
+    AppendOps[1] = 0;
+    AppendOps.push_back(dwarf::DW_OP_plus);
+    AppendExpr = DIExpression::append(Expr, AppendOps);
+    OpsRes[2] = dwarf::DW_OP_constu;
+    OpsRes[3] = Ops[3];
----------------
jmorse wrote:

Nit: working out what's in OpsRes between each test is going to place a reading-burden on someone who has to come and read this test, IMO it's better to re-declare a new vector and initialize-list it, rather than let state drift across EXPECT sections.

https://github.com/llvm/llvm-project/pull/71719


More information about the llvm-commits mailing list