[all-commits] [llvm/llvm-project] 119aec: [DebugInfo] Emit negative DW_AT_bit_offset in expl...

Victor Campos via All-commits all-commits at lists.llvm.org
Mon May 13 03:14:57 PDT 2024


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 119aecb955df91173d69c455bba0abd74271c215
      https://github.com/llvm/llvm-project/commit/119aecb955df91173d69c455bba0abd74271c215
  Author: Victor Campos <victor.campos at arm.com>
  Date:   2024-05-13 (Mon, 13 May 2024)

  Changed paths:
    M llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
    M llvm/test/DebugInfo/ARM/bitfield.ll
    M llvm/test/DebugInfo/NVPTX/packed_bitfields.ll
    M llvm/test/DebugInfo/X86/packed_bitfields.ll

  Log Message:
  -----------
  [DebugInfo] Emit negative DW_AT_bit_offset in explicit signed form (#87994)

Before this patch, the value of DW_AT_bit_offset, used for bitfields
before DWARF version 4, was always emitted as an unsigned integer using
the form DW_FORM_data<n>. If the value was originally a signed integer,
for instance in the case of negative offsets, it was up to debug
information consumers to re-cast it to a signed integer.

This is problematic since the burden of deciding if the value should be
read as signed or unsigned was put onto the debug info consumers: the
DWARF specification doesn't define DW_AT_bit_offset's underlying type.
If a debugger decided to interpret this attribute in the form data<n> as
unsigned, then negative offsets would be completely broken.

The DWARF specification version 3 mentions in the Data Representation
section, page 127:

> If one of the DW_FORM_data<n> forms is used to represent a signed or
unsigned integer, it can be hard for a consumer to discover the context
necessary to determine which interpretation is intended. Producers are
therefore strongly encouraged to use DW_FORM_sdata or DW_FORM_udata for
signed and unsigned integers respectively, rather than DW_FORM_data<n>.

Therefore, the proposal is to use DW_FORM_sdata, which is explicitly
signed. This is an indication to consumers that the offset must be
parsed unambiguously as a signed integer.

Finally, gcc already uses DW_FORM_sdata for negative offsets, fixing the
potential ambiguity altogether.

This patch mimics gcc's behaviour by emitting negative values of
DW_AT_bit_offset using the DW_FORM_sdata form. This eliminates any
potential misinterpretation.

One could argue that all values should use DW_FORM_sdata, but for the
sake of parity with gcc, it is safe to restrict the change to negative
values.



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