Skip to content

Commit

Permalink
test: check @TagName() in callconv C function
Browse files Browse the repository at this point in the history
This is a regression test for an x86_64 backend miscompilation when
using @TagName() in a callconv(.c) function with -fPIC.
  • Loading branch information
ifreund committed Feb 7, 2025
1 parent 043e3b2 commit 87bbb49
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions test/behavior/enum.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1070,6 +1070,23 @@ test "tag name with signed enum values" {
try expect(mem.eql(u8, @tagName(b), "bravo"));
}

test "@tagName in callconv(.c) function" {
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest;
if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;

try expect(mem.orderZ(u8, testEnumTagNameCallconvC(), "Two") == .eq);
comptime assert(mem.orderZ(u8, testEnumTagNameCallconvC(), "Two") == .eq);
}

fn testEnumTagNameCallconvC() callconv(.c) [*:0]const u8 {
var e: BareNumber = .Two;
_ = &e;
return @tagName(e);
}

test "enum literal casting to optional" {
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
Expand Down

0 comments on commit 87bbb49

Please sign in to comment.