Skip to content

Incorrect array lower bound in DWARF debug info #23898

Closed
@al13n321

Description

@al13n321

Zig Version

0.14.0

Steps to Reproduce and Observed Behavior

Debug info for some struct in Zig standard library, built on Linux:

% cat b.zig
const std = @import("std");
pub fn main() !void {}

% zig build-exe b.zig

% llvm-dwarfdump-18 b | grep -A4 -B18 -m1 DW_AT_lower_bound 
0x000000dc:   DW_TAG_structure_type
                DW_AT_name	("Target.Cpu.Feature.Set")
                DW_AT_byte_size	(0x28)
                DW_AT_alignment	(8)

0x000000e3:     DW_TAG_member
                  DW_AT_name	("ints")
                  DW_AT_type	(0x000000ef "usize[5]")
                  DW_AT_alignment	(8)
                  DW_AT_data_member_location	(0x00)

0x000000ee:     NULL

0x000000ef:   DW_TAG_array_type
                DW_AT_type	(0x000000fd "usize")

0x000000f4:     DW_TAG_subrange_type
                  DW_AT_type	(0x00000104 "__ARRAY_SIZE_TYPE__")
                  DW_AT_lower_bound	(-3539)
                  DW_AT_count	(0x05)

0x000000fc:     NULL

This DW_AT_lower_bound seems to say that the indexing of array Target.Cpu.Feature.Set.ints (presumably in zig/lib/std/Target.zig in the standard library) starts at -3539. It looks like a regular array, pretty sure its indexes are 0-based rather than -3539-based.

Reproduces with -fno-llvm -fno-lld as well, but the value is 1759 instead of -3539.

(I think I also reproduced it with an array in my own program, where I confirmed with debugger that indexing starts at zero, i.e. no weird advanced optimization happened where the index has to be adjusted or something. But the repro was inconsistent and stopped working at some point, and I gave up. Either it's nondeterministic or I've gone mad from staring at dwarfdump outputs for too long.)

Expected Behavior

No DW_AT_lower_bound attribute.

Metadata

Metadata

Assignees

No one assigned

    Labels

    backend-llvmThe LLVM backend outputs an LLVM IR Module.bugObserved behavior contradicts documented or intended behaviordebug-infoDebug information of binary generated by Zig is not as expected.regressionIt worked in a previous version of Zig, but stopped working.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions