motiejus/zig

fork of https://codeberg.org/ziglang/zig
git clone https://git.jakstys.lt/motiejus/zig.git
Log | Tree | Refs | README | LICENSE

commit 0914e0a4ecabc1c9f4b4a8675955ab634065449e (tree)
parent 31e755df6f3ae7e7c5a1457ca69f2d2cfb0af415
Author: Jakub Konka <kubkon@jakubkonka.com>
Date:   Thu, 10 Nov 2022 09:36:45 +0100

dwarf: do not assume unsigned 64bit integer for the enum value

Diffstat:
Msrc/link/Dwarf.zig | 5++++-
Mtest/behavior/enum.zig | 2--
2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/src/link/Dwarf.zig b/src/link/Dwarf.zig @@ -405,8 +405,11 @@ pub const DeclState = struct { const value: u64 = if (values) |vals| value: { if (vals.count() == 0) break :value @intCast(u64, field_i); // auto-numbered const value = vals.keys()[field_i]; + // TODO do not assume a 64bit enum value - could be bigger. + // See https://github.com/ziglang/zig/issues/645 var int_buffer: Value.Payload.U64 = undefined; - break :value value.enumToInt(ty, &int_buffer).toUnsignedInt(target); + const field_int_val = value.enumToInt(ty, &int_buffer); + break :value @bitCast(u64, field_int_val.toSignedInt()); } else @intCast(u64, field_i); mem.writeInt(u64, dbg_info_buffer.addManyAsArrayAssumeCapacity(8), value, target_endian); } diff --git a/test/behavior/enum.zig b/test/behavior/enum.zig @@ -1146,8 +1146,6 @@ test "size of enum with only one tag which has explicit integer tag type" { } test "switch on an extern enum with negative value" { - // TODO x86, wasm backends fail because they assume that enum tag types are unsigned - if (@import("builtin").zig_backend == .stage2_x86_64) return error.SkipZigTest; if (@import("builtin").zig_backend == .stage2_wasm) return error.SkipZigTest; const Foo = enum(c_int) {