From a242906696a29b7ce251bd416bb995ca37e95d92 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Thu, 28 Apr 2022 20:39:33 -0700 Subject: [PATCH] compiler-rt: restore stage1 workaround 18d6523888ef08bc66eb808075d13c5e00b8fcf4 regressed compiler-rt tests for stage1 because it removed a workaround. I updated the comment to better explain what exactly the workaround is so that it won't happen again. --- lib/std/special/compiler_rt/clzsi2_test.zig | 32 ++++++++++++--------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/lib/std/special/compiler_rt/clzsi2_test.zig b/lib/std/special/compiler_rt/clzsi2_test.zig index 9ad5d3afe7..ef64e24fe1 100644 --- a/lib/std/special/compiler_rt/clzsi2_test.zig +++ b/lib/std/special/compiler_rt/clzsi2_test.zig @@ -3,20 +3,24 @@ const clz = @import("count0bits.zig"); const testing = @import("std").testing; fn test__clzsi2(a: u32, expected: i32) !void { - const nakedClzsi2 = clz.__clzsi2; - const fnProto = fn (a: i32) callconv(.C) i32; - const fnProtoPtr = switch (builtin.zig_backend) { - .stage1 => fnProto, - else => *const fnProto, - }; - const fn_ptr = switch (builtin.zig_backend) { - .stage1 => nakedClzsi2, - else => &nakedClzsi2, - }; - const actualClzsi2 = @ptrCast(fnProtoPtr, fn_ptr); - const x = @bitCast(i32, a); - const result = actualClzsi2(x); - try testing.expectEqual(expected, result); + // stage1 and stage2 diverge on function pointer semantics + switch (builtin.zig_backend) { + .stage1 => { + // Use of `var` here is working around a stage1 bug. + var nakedClzsi2 = clz.__clzsi2; + var actualClzsi2 = @ptrCast(fn (a: i32) callconv(.C) i32, nakedClzsi2); + var x = @bitCast(i32, a); + var result = actualClzsi2(x); + try testing.expectEqual(expected, result); + }, + else => { + const nakedClzsi2 = clz.__clzsi2; + const actualClzsi2 = @ptrCast(*const fn (a: i32) callconv(.C) i32, &nakedClzsi2); + const x = @bitCast(i32, a); + const result = actualClzsi2(x); + try testing.expectEqual(expected, result); + }, + } } test "clzsi2" {