From 9b5737b5a6c6dab61917d17ce9eec35e5978942b Mon Sep 17 00:00:00 2001 From: Daniele Cocca Date: Sun, 13 Mar 2022 11:52:58 +0000 Subject: [PATCH 1/3] s/testClz/testCtz/g The test name here was likely the result of a bad copy-paste, as the test code is actually testing for trailing zeroes, not leading zeroes. --- test/behavior/bugs/2114.zig | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/behavior/bugs/2114.zig b/test/behavior/bugs/2114.zig index 1fc7016f44..5a71c92e8e 100644 --- a/test/behavior/bugs/2114.zig +++ b/test/behavior/bugs/2114.zig @@ -7,11 +7,11 @@ fn ctz(x: anytype) usize { } test "fixed" { - try testClz(); - comptime try testClz(); + try testCtz(); + comptime try testCtz(); } -fn testClz() !void { +fn testCtz() !void { try expect(ctz(@as(u128, 0x40000000000000000000000000000000)) == 126); try expect(math.rotl(u128, @as(u128, 0x40000000000000000000000000000000), @as(u8, 1)) == @as(u128, 0x80000000000000000000000000000000)); try expect(ctz(@as(u128, 0x80000000000000000000000000000000)) == 127); From 79f74943b525daa06f2b2c3d460da97a88aee5bb Mon Sep 17 00:00:00 2001 From: Daniele Cocca Date: Tue, 15 Mar 2022 10:20:24 +0000 Subject: [PATCH 2/3] CBE: fix output of airMinMax() This was trying to output a ternary operator, but the output was broken by the lack of a '?'. --- src/codegen/c.zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/codegen/c.zig b/src/codegen/c.zig index c63cb27529..05ceb30379 100644 --- a/src/codegen/c.zig +++ b/src/codegen/c.zig @@ -2541,7 +2541,7 @@ fn airMinMax(f: *Function, inst: Air.Inst.Index, operator: [*:0]const u8) !CValu try f.writeCValue(writer, lhs); try writer.print("{s}", .{operator}); try f.writeCValue(writer, rhs); - try writer.writeAll(") "); + try writer.writeAll(") ? "); try f.writeCValue(writer, lhs); try writer.writeAll(" : "); try f.writeCValue(writer, rhs); From 71ca0b176f7a643ef7606d12f4001b445a115092 Mon Sep 17 00:00:00 2001 From: Daniele Cocca Date: Tue, 15 Mar 2022 18:45:02 +0000 Subject: [PATCH 3/3] CBE: `#undef linux` in zig.h MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Compilers will sometimes `#define linux 1` if the operating system in use is Linux. This clashes with the code produced by the C backend when processing the stdlib, e.g. std.Target.Os.VersionRange [^1] which is a struct containing a field named `linux`. The output of the C backend doesn't rely on this macro being defined, and other code also shouldn't rely on it -- e.g. quoting from the GCC documentation [^2]: """ The C standard requires that all system-specific macros be part of the reserved namespace. All names which begin with two underscores, or an underscore and a capital letter, are reserved for the compiler and library to use as they wish. However, historically system-specific macros have had names with no special prefix; for instance, it is common to find unix defined on Unix systems. [...] We are slowly phasing out all predefined macros which are outside the reserved namespace. You should never use them in new programs, and we encourage you to correct older code to use the parallel macros whenever you find it. We don’t recommend you use the system-specific macros that are in the reserved namespace, either. It is better in the long run to check specifically for features you need """ [^1]: https://github.com/ziglang/zig/blob/8c32d989c995f8675f1824fb084245b833b26223/lib/std/target.zig#L224 [^2]: https://gcc.gnu.org/onlinedocs/cpp/System-specific-Predefined-Macros.html#System-specific-Predefined-Macros --- src/link/C/zig.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/link/C/zig.h b/src/link/C/zig.h index ce22b5221f..7259ba19ce 100644 --- a/src/link/C/zig.h +++ b/src/link/C/zig.h @@ -1,3 +1,5 @@ +#undef linux + #if __STDC_VERSION__ >= 201112L #define zig_noreturn _Noreturn #define zig_threadlocal thread_local