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

John Brawn via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 9 06:53:11 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:

> So we could add DW_OP_bit_piece to LLVM, or we could emit
> 
> ```
> !DIExpression()
> !DIExpression(DW_OP_shr 8)
> ```
> 
> Which, I believe, would be supported by LLVM today without any modifications?

That would handle the bitfield offset, but wouldn't get the bitfield size right (we could use the existing CreateBindingDeclType but that can only handle cases where the bitfield size exactly matches an integer type size). 

> Regardless of which variant we choose, we probably need to add explicit support for it to SROA.cpp to make sure it gets translated correctly when the alloca gets split up again.

I'm currently working on this, should have a patch for it soon (though it looks like we only need changes in DIExpression::createFragmentExpression).


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


More information about the llvm-commits mailing list