<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/211007>211007</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[lldb] DW_OP_fbreg widens its generic result on 32-bit targets
</td>
</tr>
<tr>
<th>Labels</th>
<td>
lldb
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
firmiana402
</td>
</tr>
</table>
<pre>
[DWARF v5](https://dwarfstd.org/doc/DWARF5.pdf) Section 2.5.1.2 specifies that `DW_OP_fbreg` produces the frame-base address plus its signed displacement with the generic type. LLVM's [location-description stack extension](https://llvm.org/docs/AMDGPUDwarfExtensionAllowLocationDescriptionOnTheDwarfExpressionStack/AMDGPUDwarfExtensionAllowLocationDescriptionOnTheDwarfExpressionStack.html#a-2-5-4) instead models the result as a default-address-space memory location, but requires it to be converted to a generic value when an arithmetic operation consumes it. Under either model, i386 value arithmetic must use a 32-bit result.
LLDB adds the displacement as an `int64_t` through `Scalar` arithmetic and pushes the result without canonicalizing it to the target address width. A 32-bit frame-base value can therefore become a 64-bit scalar.
## Source Evidence
[`Evaluate_DW_OP_fbreg`](https://github.com/llvm/llvm-project/blob/main/lldb/source/Expression/DWARFExpression.cpp) currently does:
```cpp
Scalar value;
if (llvm::Error err = eval_ctx.frame->GetFrameBaseValue(value))
return err;
value += fbreg_offset;
eval_ctx.stack.push_back(value);
eval_ctx.stack.back().SetValueType(Value::ValueType::LoadAddress);
```
`fbreg_offset` is an `int64_t`, so the implicit `Scalar` operand is 64 bits. `Scalar::operator+=` promotes to the wider operand before adding, and the handler never truncates or extends the result to `8 * address_size`.
**Related to #209728, but not a duplicate.**
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJysVU2P4jgQ_TXmUiIKzgdw4BCWZi49mtH0fByRY1eIdxM7a1fo6fn1KzsBGu1cVlopUnecqlevHq_Kwnt9Nog7VuxZcViIkVrrdo12vRZG5Clf1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