[PATCH] D157479: [Clang][DebugInfo] Emit narrower base types for structured binding declarations that bind to struct bitfields

Victor Campos via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Aug 9 01:41:12 PDT 2023


vhscampos created this revision.
Herald added a project: All.
vhscampos requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

In cases where a structured binding declaration is made to a struct with
bitfields:

struct A {

  unsigned int x : 16;
  unsigned int y : 16;

} g;

auto [a, b] = g; // structured binding declaration

Clang assigns the 'unsigned int' DWARF base type to 'a' and 'b' because
this is their deduced C++ type in the structured binding declaration.

However, their actual type in memory is 'unsigned short' as they have 16
bits allocated for each.

This is a problem for debug information consumers: if the debug
information for 'a' has the 'unsigned int' base type, a debugger will
assume it has 4 bytes, whereas it actually has a length of 2, resulting
in a read (or write) past its length.

This patch mimics GCC's behaviour: in case of structured bindings to
bitfields, the binding declaration's DWARF base type is of the target's
integer type with the same bitwidth as the bitfield.

If no suitable integer type is found in the target, no debug information
is emitted anymore in order to prevent wrong debug output.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D157479

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/CodeGen/CGDebugInfo.h
  clang/test/CodeGenCXX/debug-info-structured-binding-bitfield.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D157479.548513.patch
Type: text/x-patch
Size: 13753 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230809/9e99e27d/attachment.bin>


More information about the cfe-commits mailing list