diff options
| author | Isaac Freund <mail@isaacfreund.com> | 2025-02-06 11:52:04 +0100 |
|---|---|---|
| committer | Isaac Freund <mail@isaacfreund.com> | 2025-02-07 07:20:53 +0100 |
| commit | 87bbb49d5facb7144a50672ab20b3c9fc3da9186 (patch) | |
| tree | 682e74628b45487c1e552a045074ca4eee3f67cd /test/behavior/enum.zig | |
| parent | 043e3b29cec156dd547d2cec15dec90271c2349b (diff) | |
| download | zig-87bbb49d5facb7144a50672ab20b3c9fc3da9186.tar.gz zig-87bbb49d5facb7144a50672ab20b3c9fc3da9186.zip | |
test: check @tagName() in callconv C function
This is a regression test for an x86_64 backend miscompilation when
using @tagName() in a callconv(.c) function with -fPIC.
Diffstat (limited to 'test/behavior/enum.zig')
| -rw-r--r-- | test/behavior/enum.zig | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/test/behavior/enum.zig b/test/behavior/enum.zig index 05e2f76e16..4cbb685cf2 100644 --- a/test/behavior/enum.zig +++ b/test/behavior/enum.zig @@ -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; |
