[all-commits] [llvm/llvm-project] 0740ce: [DebugInfo] Clear subregister mask state after use...
firmiana via All-commits
all-commits at lists.llvm.org
Fri Aug 7 03:06:42 PDT 2026
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: 0740cedd9af7b94f295aca3aee9222c4d942284f
https://github.com/llvm/llvm-project/commit/0740cedd9af7b94f295aca3aee9222c4d942284f
Author: firmiana <firmiana402 at gmail.com>
Date: 2026-08-07 (Fri, 07 Aug 2026)
Changed paths:
M llvm/lib/CodeGen/AsmPrinter/DwarfExpression.cpp
M llvm/lib/CodeGen/AsmPrinter/DwarfExpression.h
A llvm/test/DebugInfo/X86/diarglist-subregister-mask.ll
Log Message:
-----------
[DebugInfo] Clear subregister mask state after use (#206428)
## Summary
This patch fixes a DWARF debug-info emission bug where the pending
subregister mask state used for one `DW_OP_LLVM_arg` could leak into a
following full-register `DW_OP_LLVM_arg` in the same `DIArgList`
expression.
For example, when an `i32` value is described through the x86-64
super-register `RDI`, LLVM correctly emits:
```text
DW_OP_breg5 RDI+0
DW_OP_constu 0xffffffff
DW_OP_and
```
However, before this patch, the subregister state remained live after
emitting that mask. If the next `DW_OP_LLVM_arg` used a full 64-bit
register such as `RSI`, LLVM could incorrectly emit the same 32-bit mask
for it too:
```text
DW_OP_breg4 RSI+0
DW_OP_constu 0xffffffff
DW_OP_and
```
## Reproducer
Source code:
```c
#include <stdint.h>
volatile int sinki;
volatile uint64_t sinku64;
__attribute__((noinline))
int test(int32_t a, uint64_t b) {
int x = a == b;
sinki += a;
sinku64 += b;
return 0;
}
int main(void) {
return test(-1, UINT64_MAX);
}
```
Compile with: `clang -O2 -g -gdwarf-5 repro.c -o repro`
DebugInfo in IR for variable `x` (still correct at this point):
```
#dbg_value(!DIArgList(i32 %a, i64 %b), !x,
!DIExpression(DW_OP_LLVM_arg, 0,
DW_OP_LLVM_convert, 32, DW_ATE_signed,
DW_OP_LLVM_convert, 64, DW_ATE_signed,
DW_OP_LLVM_arg, 1,
DW_OP_eq,
DW_OP_LLVM_convert, 1, DW_ATE_unsigned,
DW_OP_LLVM_convert, 32, DW_ATE_unsigned,
DW_OP_stack_value), !loc)
```
Emitted DWARF Expression in binary:
```text
# get value of a
DW_OP_breg5 RDI+0
DW_OP_constu 0xffffffff
DW_OP_and
DW_OP_convert <signed_32>
DW_OP_convert <signed_64>
# get value of b (wrong)
DW_OP_breg4 RSI+0
DW_OP_constu 0xffffffff
DW_OP_and
# comparison
DW_OP_eq
DW_OP_stack_value
```
With the buggy DWARF expression, LLDB can evaluate `x` as `0`, even
though the source-level value is `1`.
## Fix
`DwarfExpression::maskSubRegister()` consumes the pending subregister
description when it emits the mask. This patch clears that state inside
`maskSubRegister()` after emitting the shift/mask operations, preventing
it from affecting later operands in the same expression.
A regression test (`test/DebugInfo/X86/diarglist-subregister-mask.ll`)
was added to check that the first subregister operand is masked, while
the following full-register operand is not.
## Validation
Locally verified with:
```
llvm-lit -sv llvm/test/DebugInfo/X86/diarglist-subregister-mask.ll
ninja -C build check-llvm
ninja -C build check-lldb
```
Both `check-llvm` and `check-lldb` completed with no unexpected
failures.
To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications
More information about the All-commits
mailing list