[all-commits] [llvm/llvm-project] d77cba: [Clang][DebugInfo] Emit narrower base types for st...

Victor Campos via All-commits all-commits at lists.llvm.org
Wed Aug 16 02:45:16 PDT 2023

  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: d77cba6d474ab8ce5ece126499522de414c8089c
  Author: Victor Campos <victor.campos at arm.com>
  Date:   2023-08-16 (Wed, 16 Aug 2023)

  Changed paths:
    M clang/lib/CodeGen/CGDebugInfo.cpp
    M clang/lib/CodeGen/CGDebugInfo.h
    A clang/test/CodeGenCXX/debug-info-structured-binding-bitfield.cpp

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

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

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.

Reviewed By: tmatheson

Differential Revision: https://reviews.llvm.org/D157479

More information about the All-commits mailing list