authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-04-28 20:39:33-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-04-28 20:39:33-07:00
loga242906696a29b7ce251bd416bb995ca37e95d92
tree92ff2eef4dcf3bd698d327dcf7789cbc6bf56376
parentd8e99164d35fbbcd7e33773e9f35be70d184eaf5

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.

1 files changed, 18 insertions(+), 14 deletions(-)

lib/std/special/compiler_rt/clzsi2_test.zig+18-14
...@@ -3,20 +3,24 @@ const clz = @import("count0bits.zig");...@@ -3,20 +3,24 @@ const clz = @import("count0bits.zig");
3const testing = @import("std").testing;3const testing = @import("std").testing;
44
5fn test__clzsi2(a: u32, expected: i32) !void {5fn test__clzsi2(a: u32, expected: i32) !void {
6 const nakedClzsi2 = clz.__clzsi2;6 // stage1 and stage2 diverge on function pointer semantics
7 const fnProto = fn (a: i32) callconv(.C) i32;7 switch (builtin.zig_backend) {
8 const fnProtoPtr = switch (builtin.zig_backend) {8 .stage1 => {
9 .stage1 => fnProto,9 // Use of `var` here is working around a stage1 bug.
10 else => *const fnProto,10 var nakedClzsi2 = clz.__clzsi2;
11 };11 var actualClzsi2 = @ptrCast(fn (a: i32) callconv(.C) i32, nakedClzsi2);
12 const fn_ptr = switch (builtin.zig_backend) {12 var x = @bitCast(i32, a);
13 .stage1 => nakedClzsi2,13 var result = actualClzsi2(x);
14 else => &nakedClzsi2,14 try testing.expectEqual(expected, result);
15 };15 },
16 const actualClzsi2 = @ptrCast(fnProtoPtr, fn_ptr);16 else => {
17 const x = @bitCast(i32, a);17 const nakedClzsi2 = clz.__clzsi2;
18 const result = actualClzsi2(x);18 const actualClzsi2 = @ptrCast(*const fn (a: i32) callconv(.C) i32, &nakedClzsi2);
19 try testing.expectEqual(expected, result);19 const x = @bitCast(i32, a);
20 const result = actualClzsi2(x);
21 try testing.expectEqual(expected, result);
22 },
23 }
20}24}
2125
22test "clzsi2" {26test "clzsi2" {