https://github.com/MrEven132 created https://github.com/llvm/llvm-project/pull/216666
`DW_OP_deref` and `DW_OP_deref_size` produce the DWARF generic type, but the ordinary memory paths left the `uint64_t` returned by `GetMaxU64` on the expression stack. This made their results 64 bits even when evaluating an expression for a 32-bit target. Normalize successful memory dereference results to the target address width using unsigned extension. Add i386 unit coverage for both operations, including the `DW_OP_deref_size` zero-extension behavior and explicit APSInt width checks. Fixes #210991. >From 28ebe5eafb62fe331c51356ea3a03de3c2085c41 Mon Sep 17 00:00:00 2001 From: MrEven132 <[email protected]> Date: Mon, 17 Aug 2026 17:25:54 +0800 Subject: [PATCH] fix lldb deref generic width --- lldb/source/Expression/DWARFExpression.cpp | 3 +++ .../Expression/DWARFExpressionTest.cpp | 21 +++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/lldb/source/Expression/DWARFExpression.cpp b/lldb/source/Expression/DWARFExpression.cpp index f4c4f519b09c7..c0f3b83d8bc1b 100644 --- a/lldb/source/Expression/DWARFExpression.cpp +++ b/lldb/source/Expression/DWARFExpression.cpp @@ -1095,6 +1095,9 @@ static llvm::Error Evaluate_DW_OP_deref(EvalContext &eval_ctx, return llvm::createStringError("invalid value for %s", op_name); } + // Both operations push a generic, address-sized result. + eval_ctx.stack.back().GetScalar().TruncOrExtendTo(size_addr_bytes * 8, + /*sign=*/false); return llvm::Error::success(); } diff --git a/lldb/unittests/Expression/DWARFExpressionTest.cpp b/lldb/unittests/Expression/DWARFExpressionTest.cpp index c2752e16672f7..7c03ba275419d 100644 --- a/lldb/unittests/Expression/DWARFExpressionTest.cpp +++ b/lldb/unittests/Expression/DWARFExpressionTest.cpp @@ -1399,6 +1399,27 @@ TEST_F(DWARFExpressionMockProcessTest, DW_OP_deref) { ExpectScalar(Scalar(4))); } +TEST_F(DWARFExpressionMockProcessTest, DW_OP_deref_address_size) { + MockMemory::Map memory = { + {{0x4, 4}, {0x2a, 0x00, 0x00, 0x00}}, + {{0x8, 1}, {0xff}}, + }; + TestContext test_ctx; + ASSERT_TRUE( + CreateTestContext(&test_ctx, "i386-pc-linux", {}, std::move(memory))); + ExecutionContext exe_ctx(test_ctx.process_sp); + + auto deref_result = + Evaluate({DW_OP_lit4, DW_OP_deref, DW_OP_stack_value}, {}, {}, &exe_ctx); + ASSERT_THAT_EXPECTED(deref_result, ExpectScalar(32, 0x2a, false)); + EXPECT_EQ(deref_result->GetScalar().GetAPSInt().getBitWidth(), 32u); + + auto deref_size_result = Evaluate( + {DW_OP_lit8, DW_OP_deref_size, 1, DW_OP_stack_value}, {}, {}, &exe_ctx); + ASSERT_THAT_EXPECTED(deref_size_result, ExpectScalar(32, 0xff, false)); + EXPECT_EQ(deref_size_result->GetScalar().GetAPSInt().getBitWidth(), 32u); +} + TEST_F(DWARFExpressionMockProcessTest, WASM_DW_OP_addr) { // Set up a wasm target TestContext test_ctx; _______________________________________________ lldb-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
