[clang] [llvm] [DebugInfo] Use DW_op_bit_piece for structured bindings of bitfields (PR #85665)

John Brawn via cfe-commits cfe-commits at lists.llvm.org
Tue Mar 19 03:42:37 PDT 2024


================
@@ -8,8 +8,8 @@ struct S0 {
 // CHECK-LABEL: define dso_local void @_Z3fS0v
 // CHECK:                        alloca %struct.S0, align 4
 // CHECK-NEXT:    [[TMP0:%.*]] = alloca %struct.S0, align 4
-// CHECK:         call void @llvm.dbg.declare(metadata ptr [[TMP0]], metadata [[S0_A:![0-9]+]], metadata !DIExpression())
-// CHECK-NEXT:    call void @llvm.dbg.declare(metadata ptr [[TMP0]], metadata [[S0_B:![0-9]+]], metadata !DIExpression(DW_OP_plus_uconst, 2))
+// CHECK:         call void @llvm.dbg.declare(metadata ptr [[TMP0]], metadata [[S0_A:![0-9]+]], metadata !DIExpression(DW_OP_bit_piece, 16, 0))
----------------
john-brawn-arm wrote:

The LLVM langref says "Note that contrary to DW_OP_bit_piece, the offset is describing the location within the described source variable". What I think this means is that while DW_OP_bit_piece means "you get the source variable by extracting these bits of this location", DW_OP_LLVM_fragment means "the value of this location is these bits of the source variable".

Trying out DW_OP_LLVM_fragment in
```
struct {
  unsigned int a : 8;
  unsigned int b : 8;
} X = { 1, 2 };

int main() {
  auto [a, b] = X;
  return a + b;
}
```
the resulting dwarf info looks pretty strange
```
 <2><7f>: Abbrev Number: 7 (DW_TAG_variable)
    <80>   DW_AT_location    : 4 byte block: 93 1 91 78         (DW_OP_piece: 1; DW_OP_fbreg: -8)
    <85>   DW_AT_name        : (indirect string, offset: 0x9c): a
    <89>   DW_AT_decl_file   : 1
    <8a>   DW_AT_decl_line   : 7
    <8b>   DW_AT_type        : <0x5f>
 <2><8f>: Abbrev Number: 7 (DW_TAG_variable)
    <90>   DW_AT_location    : 6 byte block: 93 1 91 78 93 1    (DW_OP_piece: 1; DW_OP_fbreg: -8; DW_OP_piece: 1)
    <97>   DW_AT_name        : (indirect string, offset: 0xab): b
    <9b>   DW_AT_decl_file   : 1
    <9c>   DW_AT_decl_line   : 7
    <9d>   DW_AT_type        : <0x5f>
```
lldb says (at line 8)
```
(lldb) p a
(unsigned int) 513
(lldb) p b
(unsigned int) 256
```
gdb appears to not like this dwarf info and just says
```
(gdb) p a
$1 = <optimized out>
(gdb) p b
$2 = <optimized out>
```

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


More information about the cfe-commits mailing list