commit 87bbb49d5facb7144a50672ab20b3c9fc3da9186 (tree)
parent 043e3b29cec156dd547d2cec15dec90271c2349b
Author: Isaac Freund <mail@isaacfreund.com>
Date: Thu, 6 Feb 2025 11:52:04 +0100
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:
1 file changed, 17 insertions(+), 0 deletions(-)
diff --git 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;