| author | |
| committer | |
| log | 317d1ecb2cf3234b0259daf6cc0baac7d86264e2 |
| tree | 17c8c50e096fd23e0f9b9194a8a6ac0b8a028711 |
| parent | fcadeb50c04199fce2d9675ba2976680c71c67ff |
| parent | 16be70cbbf8e6dc658b9fcacd3366df8f83fffa8 |
| signature |
9 files changed, 139 insertions(+), 18 deletions(-)
build.zig+6-3| ... | ... | @@ -122,16 +122,19 @@ pub fn build(b: *Builder) !void { |
| 122 | 122 | } |
| 123 | 123 | const modes = chosen_modes[0..chosen_mode_index]; |
| 124 | 124 | |
| 125 | const multi_and_single = [_]bool{ false, true }; | |
| 126 | const just_multi = [_]bool{false}; | |
| 127 | ||
| 125 | 128 | // run stage1 `zig fmt` on this build.zig file just to make sure it works |
| 126 | 129 | test_step.dependOn(&fmt_build_zig.step); |
| 127 | 130 | const fmt_step = b.step("test-fmt", "Run zig fmt against build.zig to make sure it works"); |
| 128 | 131 | fmt_step.dependOn(&fmt_build_zig.step); |
| 129 | 132 | |
| 130 | test_step.dependOn(tests.addPkgTests(b, test_filter, "test/stage1/behavior.zig", "behavior", "Run the behavior tests", modes, skip_non_native)); | |
| 133 | test_step.dependOn(tests.addPkgTests(b, test_filter, "test/stage1/behavior.zig", "behavior", "Run the behavior tests", modes, multi_and_single, skip_non_native)); | |
| 131 | 134 | |
| 132 | test_step.dependOn(tests.addPkgTests(b, test_filter, "std/std.zig", "std", "Run the standard library tests", modes, skip_non_native)); | |
| 135 | test_step.dependOn(tests.addPkgTests(b, test_filter, "std/std.zig", "std", "Run the standard library tests", modes, multi_and_single, skip_non_native)); | |
| 133 | 136 | |
| 134 | test_step.dependOn(tests.addPkgTests(b, test_filter, "std/special/compiler_rt.zig", "compiler-rt", "Run the compiler_rt tests", modes, skip_non_native)); | |
| 137 | test_step.dependOn(tests.addPkgTests(b, test_filter, "std/special/compiler_rt.zig", "compiler-rt", "Run the compiler_rt tests", modes, just_multi, skip_non_native)); | |
| 135 | 138 | |
| 136 | 139 | test_step.dependOn(tests.addCompareOutputTests(b, test_filter, modes)); |
| 137 | 140 | test_step.dependOn(tests.addStandaloneTests(b, test_filter, modes)); |
src/analyze.cpp+2-1| ... | ... | @@ -3346,7 +3346,8 @@ static void resolve_use_decl(CodeGen *g, TldUsingNamespace *tld_using_namespace, |
| 3346 | 3346 | |
| 3347 | 3347 | static void preview_use_decl(CodeGen *g, TldUsingNamespace *using_namespace, ScopeDecls *dest_decls_scope) { |
| 3348 | 3348 | if (using_namespace->base.resolution == TldResolutionOk || |
| 3349 | using_namespace->base.resolution == TldResolutionInvalid) | |
| 3349 | using_namespace->base.resolution == TldResolutionInvalid || | |
| 3350 | using_namespace->using_namespace_value != nullptr) | |
| 3350 | 3351 | { |
| 3351 | 3352 | return; |
| 3352 | 3353 | } |
std/build.zig+20-11| ... | ... | @@ -41,9 +41,11 @@ pub const Builder = struct { |
| 41 | 41 | env_map: *BufMap, |
| 42 | 42 | top_level_steps: ArrayList(*TopLevelStep), |
| 43 | 43 | install_prefix: ?[]const u8, |
| 44 | search_prefixes: ArrayList([]const u8), | |
| 44 | dest_dir: ?[]const u8, | |
| 45 | 45 | lib_dir: ?[]const u8, |
| 46 | 46 | exe_dir: ?[]const u8, |
| 47 | install_path: []const u8, | |
| 48 | search_prefixes: ArrayList([]const u8), | |
| 47 | 49 | installed_files: ArrayList(InstalledFile), |
| 48 | 50 | build_root: []const u8, |
| 49 | 51 | cache_root: []const u8, |
| ... | ... | @@ -125,10 +127,11 @@ pub const Builder = struct { |
| 125 | 127 | .top_level_steps = ArrayList(*TopLevelStep).init(allocator), |
| 126 | 128 | .default_step = undefined, |
| 127 | 129 | .env_map = env_map, |
| 128 | .install_prefix = null, | |
| 129 | 130 | .search_prefixes = ArrayList([]const u8).init(allocator), |
| 131 | .install_prefix = null, | |
| 130 | 132 | .lib_dir = null, |
| 131 | 133 | .exe_dir = null, |
| 134 | .dest_dir = env_map.get("DESTDIR"), | |
| 132 | 135 | .installed_files = ArrayList(InstalledFile).init(allocator), |
| 133 | 136 | .install_tls = TopLevelStep{ |
| 134 | 137 | .step = Step.initNoOp("install", allocator), |
| ... | ... | @@ -142,6 +145,7 @@ pub const Builder = struct { |
| 142 | 145 | .is_release = false, |
| 143 | 146 | .override_std_dir = null, |
| 144 | 147 | .override_lib_dir = null, |
| 148 | .install_path = undefined, | |
| 145 | 149 | }; |
| 146 | 150 | try self.top_level_steps.append(&self.install_tls); |
| 147 | 151 | try self.top_level_steps.append(&self.uninstall_tls); |
| ... | ... | @@ -164,14 +168,19 @@ pub const Builder = struct { |
| 164 | 168 | } |
| 165 | 169 | |
| 166 | 170 | fn resolveInstallPrefix(self: *Builder) void { |
| 167 | const prefix = if (self.install_prefix) |prefix| prefix else blk: { | |
| 168 | const prefix = self.cache_root; | |
| 169 | self.install_prefix = prefix; | |
| 170 | break :blk prefix; | |
| 171 | }; | |
| 172 | ||
| 173 | self.lib_dir = fs.path.join(self.allocator, [_][]const u8{ prefix, "lib" }) catch unreachable; | |
| 174 | self.exe_dir = fs.path.join(self.allocator, [_][]const u8{ prefix, "bin" }) catch unreachable; | |
| 171 | if (self.dest_dir) |dest_dir| { | |
| 172 | const install_prefix = self.install_prefix orelse "/usr"; | |
| 173 | self.install_path = fs.path.join(self.allocator, [_][]const u8{ dest_dir, install_prefix }) catch unreachable; | |
| 174 | } else { | |
| 175 | const install_prefix = self.install_prefix orelse blk: { | |
| 176 | const p = self.cache_root; | |
| 177 | self.install_prefix = p; | |
| 178 | break :blk p; | |
| 179 | }; | |
| 180 | self.install_path = install_prefix; | |
| 181 | } | |
| 182 | self.lib_dir = fs.path.join(self.allocator, [_][]const u8{ self.install_path, "lib" }) catch unreachable; | |
| 183 | self.exe_dir = fs.path.join(self.allocator, [_][]const u8{ self.install_path, "bin" }) catch unreachable; | |
| 175 | 184 | } |
| 176 | 185 | |
| 177 | 186 | pub fn addExecutable(self: *Builder, name: []const u8, root_src: ?[]const u8) *LibExeObjStep { |
| ... | ... | @@ -884,7 +893,7 @@ pub const Builder = struct { |
| 884 | 893 | |
| 885 | 894 | fn getInstallPath(self: *Builder, dir: InstallDir, dest_rel_path: []const u8) []const u8 { |
| 886 | 895 | const base_dir = switch (dir) { |
| 887 | .Prefix => self.install_prefix.?, | |
| 896 | .Prefix => self.install_path, | |
| 888 | 897 | .Bin => self.exe_dir.?, |
| 889 | 898 | .Lib => self.lib_dir.?, |
| 890 | 899 | }; |
std/debug.zig+1-1| ... | ... | @@ -2353,7 +2353,7 @@ pub fn attachSegfaultHandler() void { |
| 2353 | 2353 | fn resetSegfaultHandler() void { |
| 2354 | 2354 | if (windows.is_the_target) { |
| 2355 | 2355 | if (windows_segfault_handle) |handle| { |
| 2356 | assert(windows.kernel32.RemoveVectoredExceptionHandler() != 0); | |
| 2356 | assert(windows.kernel32.RemoveVectoredExceptionHandler(handle) != 0); | |
| 2357 | 2357 | windows_segfault_handle = null; |
| 2358 | 2358 | } |
| 2359 | 2359 | return; |
std/special/compiler_rt.zig+3| ... | ... | @@ -127,6 +127,7 @@ comptime { |
| 127 | 127 | @export("__udivmoddi4", @import("compiler_rt/udivmoddi4.zig").__udivmoddi4, linkage); |
| 128 | 128 | @export("__popcountdi2", @import("compiler_rt/popcountdi2.zig").__popcountdi2, linkage); |
| 129 | 129 | |
| 130 | @export("__muldi3", @import("compiler_rt/muldi3.zig").__muldi3, linkage); | |
| 130 | 131 | @export("__divmoddi4", __divmoddi4, linkage); |
| 131 | 132 | @export("__divsi3", __divsi3, linkage); |
| 132 | 133 | @export("__divdi3", __divdi3, linkage); |
| ... | ... | @@ -147,6 +148,8 @@ comptime { |
| 147 | 148 | @export("__aeabi_unwind_cpp_pr1", __aeabi_unwind_cpp_pr1, linkage); |
| 148 | 149 | @export("__aeabi_unwind_cpp_pr2", __aeabi_unwind_cpp_pr2, linkage); |
| 149 | 150 | |
| 151 | @export("__aeabi_lmul", @import("compiler_rt/muldi3.zig").__muldi3, linkage); | |
| 152 | ||
| 150 | 153 | @export("__aeabi_ldivmod", __aeabi_ldivmod, linkage); |
| 151 | 154 | @export("__aeabi_uldivmod", __aeabi_uldivmod, linkage); |
| 152 | 155 |
std/special/compiler_rt/divti3.zig-1| ... | ... | @@ -1,6 +1,5 @@ |
| 1 | 1 | const udivmod = @import("udivmod.zig").udivmod; |
| 2 | 2 | const builtin = @import("builtin"); |
| 3 | const compiler_rt = @import("../compiler_rt.zig"); | |
| 4 | 3 | |
| 5 | 4 | pub extern fn __divti3(a: i128, b: i128) i128 { |
| 6 | 5 | @setRuntimeSafety(builtin.is_test); |
std/special/compiler_rt/muldi3.zig created+54| ... | ... | @@ -0,0 +1,54 @@ |
| 1 | const builtin = @import("builtin"); | |
| 2 | ||
| 3 | // Ported from | |
| 4 | // https://github.com/llvm/llvm-project/blob/552c2c09d354a3ad9c1c9647e0a3bb5099c31088/compiler-rt/lib/builtins/muldi3.c | |
| 5 | ||
| 6 | const dwords = extern union { | |
| 7 | all: i64, | |
| 8 | s: switch (builtin.endian) { | |
| 9 | .Little => extern struct { | |
| 10 | low: u32, | |
| 11 | high: u32, | |
| 12 | }, | |
| 13 | .Big => extern struct { | |
| 14 | high: u32, | |
| 15 | low: u32, | |
| 16 | }, | |
| 17 | }, | |
| 18 | }; | |
| 19 | ||
| 20 | fn __muldsi3(a: u32, b: u32) i64 { | |
| 21 | @setRuntimeSafety(builtin.is_test); | |
| 22 | ||
| 23 | const bits_in_word_2 = @sizeOf(i32) * 8 / 2; | |
| 24 | const lower_mask = (~u32(0)) >> bits_in_word_2; | |
| 25 | ||
| 26 | var r: dwords = undefined; | |
| 27 | r.s.low = (a & lower_mask) *% (b & lower_mask); | |
| 28 | var t: u32 = r.s.low >> bits_in_word_2; | |
| 29 | r.s.low &= lower_mask; | |
| 30 | t += (a >> bits_in_word_2) *% (b & lower_mask); | |
| 31 | r.s.low +%= (t & lower_mask) << bits_in_word_2; | |
| 32 | r.s.high = t >> bits_in_word_2; | |
| 33 | t = r.s.low >> bits_in_word_2; | |
| 34 | r.s.low &= lower_mask; | |
| 35 | t +%= (b >> bits_in_word_2) *% (a & lower_mask); | |
| 36 | r.s.low +%= (t & lower_mask) << bits_in_word_2; | |
| 37 | r.s.high +%= t >> bits_in_word_2; | |
| 38 | r.s.high +%= (a >> bits_in_word_2) *% (b >> bits_in_word_2); | |
| 39 | return r.all; | |
| 40 | } | |
| 41 | ||
| 42 | pub extern fn __muldi3(a: i64, b: i64) i64 { | |
| 43 | @setRuntimeSafety(builtin.is_test); | |
| 44 | ||
| 45 | const x = dwords{ .all = a }; | |
| 46 | const y = dwords{ .all = b }; | |
| 47 | var r = dwords{ .all = __muldsi3(x.s.low, y.s.low) }; | |
| 48 | r.s.high +%= x.s.high *% y.s.low +% x.s.low *% y.s.high; | |
| 49 | return r.all; | |
| 50 | } | |
| 51 | ||
| 52 | test "import muldi3" { | |
| 53 | _ = @import("muldi3_test.zig"); | |
| 54 | } |
std/special/compiler_rt/muldi3_test.zig created+51| ... | ... | @@ -0,0 +1,51 @@ |
| 1 | const __muldi3 = @import("muldi3.zig").__muldi3; | |
| 2 | const testing = @import("std").testing; | |
| 3 | ||
| 4 | fn test__muldi3(a: i64, b: i64, expected: i64) void { | |
| 5 | const x = __muldi3(a, b); | |
| 6 | testing.expect(x == expected); | |
| 7 | } | |
| 8 | ||
| 9 | test "muldi3" { | |
| 10 | test__muldi3(0, 0, 0); | |
| 11 | test__muldi3(0, 1, 0); | |
| 12 | test__muldi3(1, 0, 0); | |
| 13 | test__muldi3(0, 10, 0); | |
| 14 | test__muldi3(10, 0, 0); | |
| 15 | test__muldi3(0, 81985529216486895, 0); | |
| 16 | test__muldi3(81985529216486895, 0, 0); | |
| 17 | ||
| 18 | test__muldi3(0, -1, 0); | |
| 19 | test__muldi3(-1, 0, 0); | |
| 20 | test__muldi3(0, -10, 0); | |
| 21 | test__muldi3(-10, 0, 0); | |
| 22 | test__muldi3(0, -81985529216486895, 0); | |
| 23 | test__muldi3(-81985529216486895, 0, 0); | |
| 24 | ||
| 25 | test__muldi3(1, 1, 1); | |
| 26 | test__muldi3(1, 10, 10); | |
| 27 | test__muldi3(10, 1, 10); | |
| 28 | test__muldi3(1, 81985529216486895, 81985529216486895); | |
| 29 | test__muldi3(81985529216486895, 1, 81985529216486895); | |
| 30 | ||
| 31 | test__muldi3(1, -1, -1); | |
| 32 | test__muldi3(1, -10, -10); | |
| 33 | test__muldi3(-10, 1, -10); | |
| 34 | test__muldi3(1, -81985529216486895, -81985529216486895); | |
| 35 | test__muldi3(-81985529216486895, 1, -81985529216486895); | |
| 36 | ||
| 37 | test__muldi3(3037000499, 3037000499, 9223372030926249001); | |
| 38 | test__muldi3(-3037000499, 3037000499, -9223372030926249001); | |
| 39 | test__muldi3(3037000499, -3037000499, -9223372030926249001); | |
| 40 | test__muldi3(-3037000499, -3037000499, 9223372030926249001); | |
| 41 | ||
| 42 | test__muldi3(4398046511103, 2097152, 9223372036852678656); | |
| 43 | test__muldi3(-4398046511103, 2097152, -9223372036852678656); | |
| 44 | test__muldi3(4398046511103, -2097152, -9223372036852678656); | |
| 45 | test__muldi3(-4398046511103, -2097152, 9223372036852678656); | |
| 46 | ||
| 47 | test__muldi3(2097152, 4398046511103, 9223372036852678656); | |
| 48 | test__muldi3(-2097152, 4398046511103, -9223372036852678656); | |
| 49 | test__muldi3(2097152, -4398046511103, -9223372036852678656); | |
| 50 | test__muldi3(-2097152, -4398046511103, 9223372036852678656); | |
| 51 | } |
test/tests.zig+2-1| ... | ... | @@ -170,6 +170,7 @@ pub fn addPkgTests( |
| 170 | 170 | name: []const u8, |
| 171 | 171 | desc: []const u8, |
| 172 | 172 | modes: []const Mode, |
| 173 | single_threaded_list: []const bool, | |
| 173 | 174 | skip_non_native: bool, |
| 174 | 175 | ) *build.Step { |
| 175 | 176 | const step = b.step(b.fmt("test-{}", name), desc); |
| ... | ... | @@ -179,7 +180,7 @@ pub fn addPkgTests( |
| 179 | 180 | continue; |
| 180 | 181 | for (modes) |mode| { |
| 181 | 182 | for ([_]bool{ false, true }) |link_libc| { |
| 182 | for ([_]bool{ false, true }) |single_threaded| { | |
| 183 | for (single_threaded_list) |single_threaded| { | |
| 183 | 184 | if (link_libc and !is_native) { |
| 184 | 185 | // don't assume we have a cross-compiling libc set up |
| 185 | 186 | continue; |