From 6148ec9f438e38c94ce95d5802103c7c078acff0 Mon Sep 17 00:00:00 2001 From: Jacob Young Date: Mon, 19 Oct 2026 19:07:00 -0400 Subject: [PATCH] test/llvm: combine `test-llvm-ir` and `test-llvm-targets` The IR tests should be run on the same target matrix anyway. --- build.zig | 10 +- lib/compiler/Maker/Step/Run.zig | 8 +- src/main.zig | 2 +- test/Runner.zig | 245 ++++++++++++--------- test/llvm-ir/array_to_vector | 38 ---- test/llvm-ir/dead_store | 43 ---- test/llvm-ir/load_store_bool | 28 --- test/llvm-ir/matrix.zon | 8 - test/llvm-ir/nonnull | 30 --- test/{llvm-ir => llvm}/allowzero | 28 ++- test/llvm/array_to_vector | 109 +++++++++ test/llvm/dead_store | 65 ++++++ test/{llvm-targets => llvm}/empty_analyze | 6 +- test/{llvm-targets => llvm}/empty_assembly | 6 +- test/{llvm-targets => llvm}/empty_object | 6 +- test/llvm/load_store_bool | 95 ++++++++ test/{llvm-targets => llvm}/matrix.zon | 56 ++--- test/llvm/nonnull | 44 ++++ test/{llvm-ir => llvm}/unused_load | 32 ++- 19 files changed, 565 insertions(+), 294 deletions(-) delete mode 100644 test/llvm-ir/array_to_vector delete mode 100644 test/llvm-ir/dead_store delete mode 100644 test/llvm-ir/load_store_bool delete mode 100644 test/llvm-ir/matrix.zon delete mode 100644 test/llvm-ir/nonnull rename test/{llvm-ir => llvm}/allowzero (55%) create mode 100644 test/llvm/array_to_vector create mode 100644 test/llvm/dead_store rename test/{llvm-targets => llvm}/empty_analyze (96%) rename test/{llvm-targets => llvm}/empty_assembly (96%) rename test/{llvm-targets => llvm}/empty_object (97%) create mode 100644 test/llvm/load_store_bool rename test/{llvm-targets => llvm}/matrix.zon (98%) create mode 100644 test/llvm/nonnull rename test/{llvm-ir => llvm}/unused_load (51%) diff --git a/build.zig b/build.zig index 985418a1389f8aa1bd131e3d338d88afa8600943..ed8b16da95710fd2d401cc9fc0c59c08b3462369 100644 --- a/build.zig +++ b/build.zig @@ -816,13 +816,9 @@ pub fn build(b: *std.Build) !void { try tests.addRunnerTests(b, runner, test_incremental_step, "test/incremental", @import("test/incremental/matrix.zon"), runner_opts); test_step.dependOn(test_incremental_step); - const test_llvm_ir_step = b.step("test-llvm-ir", "Run the LLVM IR tests"); - try tests.addRunnerTests(b, runner, test_llvm_ir_step, "test/llvm-ir", @import("test/llvm-ir/matrix.zon"), runner_opts); - test_step.dependOn(test_llvm_ir_step); - - const test_llvm_targets_step = b.step("test-llvm-targets", "Run the LLVM targets tests"); - try tests.addRunnerTests(b, runner, test_llvm_targets_step, "test/llvm-targets", @import("test/llvm-targets/matrix.zon"), runner_opts); - test_step.dependOn(test_llvm_targets_step); + const test_llvm_step = b.step("test-llvm", "Run the LLVM IR tests"); + try tests.addRunnerTests(b, runner, test_llvm_step, "test/llvm", @import("test/llvm/matrix.zon"), runner_opts); + test_step.dependOn(test_llvm_step); } fn addWasiUpdateStep(b: *std.Build, version: [:0]const u8) !void { diff --git a/lib/compiler/Maker/Step/Run.zig b/lib/compiler/Maker/Step/Run.zig index 73b36d1ec7ad1b592cce4ac4716193c5ac5249b5..ed55273d560d5f92f73488c7ced019414a85ac13 100644 --- a/lib/compiler/Maker/Step/Run.zig +++ b/lib/compiler/Maker/Step/Run.zig @@ -795,6 +795,7 @@ fn waitZigTest( multi_reader: *Io.File.MultiReader, opt_metadata: *?TestMetadata, results: *Step.TestResults, + eb_wip: *std.zig.ErrorBundle.Wip, ) !union(enum) { write_failed: anyerror, no_poll: struct { @@ -885,7 +886,7 @@ fn waitZigTest( .{ builtin.zig_version_string, body }, ); }, - .error_bundle => step.result_error_bundle = try std.zig.Server.allocErrorBundle(gpa, body), + .error_bundle => try eb_wip.addBundleAsRoots(try std.zig.Server.allocErrorBundle(arena, body)), .test_metadata => { // `metadata` would only be populated if we'd already seen a `test_metadata`, but we // only request it once (and importantly, we don't re-request it if we kill and @@ -1573,6 +1574,9 @@ fn evalZigTest( }; var test_metadata: ?TestMetadata = null; + var eb_wip: std.zig.ErrorBundle.Wip = try .init(gpa); + defer eb_wip.deinit(); + while (true) { var child = try process.spawn(io, spawn_options); var multi_reader_buffer: Io.File.MultiReader.Buffer(2) = undefined; @@ -1602,6 +1606,7 @@ fn evalZigTest( &multi_reader, &test_metadata, &test_results, + &eb_wip, )) { .write_failed => |err| { // The runner unexpectedly closed a stdio pipe, which means a crash. Make sure we've captured @@ -1687,6 +1692,7 @@ fn evalZigTest( } } } + step.result_error_bundle = try eb_wip.toOwnedBundle(""); return; }, .timeout => |timeout| { diff --git a/src/main.zig b/src/main.zig index 77a53032b45b49d1ee726244866ca2f2f117a27a..49838feb8beb6de697b763fc6852054050033a6e 100644 --- a/src/main.zig +++ b/src/main.zig @@ -3368,7 +3368,7 @@ fn buildOutputType( const target = &main_mod.resolved_target.result; if (target.cpu.arch == .arc or target.cpu.arch.isNvptx()) { - if (emit_bin != .no and create_module.resolved_options.use_llvm) { + if (emit_bin != .no and target.ofmt != .llvmbc and target.ofmt != .llvmir and create_module.resolved_options.use_llvm) { fatal("cannot emit {s} binary with the LLVM backend; only '-femit-asm' is supported", .{ @tagName(target.cpu.arch), }); diff --git a/test/Runner.zig b/test/Runner.zig index 858809125745c16e9f9ccc17b7c8f4d2bc245130..1d838172a23bc9e182529cb6d37305def72f4c90 100644 --- a/test/Runner.zig +++ b/test/Runner.zig @@ -17,7 +17,7 @@ pub const Target = struct { dynamic_linker: DynamicLinker = .default, cache_mode: enum { whole, incremental }, - backend: enum { selfhosted, llvm, llvmir, cbe }, + backend: enum { selfhosted, llvm, cbe }, linker: enum { lld, old, new }, pic: enum { nopic, pic, pie }, @@ -942,6 +942,7 @@ fn testOne(runner: *Runner, test_index: u32) (error{ServerWriteFailed} || TestEr }; defer { update.manifest_sr.deinit(); + if (update.compiler) |*comp| comp.deinit(); update.src_dir.close(runner.io); update.prog_node.end(); } @@ -1161,11 +1162,12 @@ fn handleCommand( const triple_cpu = component_it.rest(); var triple_len: usize = 0; for (0..3) |_| { + const component_start = triple_len; triple_len = if (std.mem.findScalarPos(u8, triple_cpu, triple_len, '-')) |dash_pos| dash_pos + 1 else return update.fail("target {q} missing cpu", .{update.target_query}); - if (std.mem.eql(u8, triple_cpu[0..triple_len], "native-")) break; + if (std.mem.eql(u8, triple_cpu[component_start..triple_len], "native-")) break; } const triple = triple_cpu[0 .. triple_len - 1]; const cpu = triple_cpu[triple_len..]; @@ -1179,7 +1181,6 @@ fn handleCommand( .cpu_features = cpu, .object_format = switch (backend) { .sema, .selfhosted, .llvm => null, - .llvmir => "llvmir", .cbe => "c", }, .diagnostics = &query_parse_diags, @@ -1393,7 +1394,6 @@ fn handleCommand( } else return update.fail("unexpected stderr:\n{s}", .{stderr_buffered}); } - try comp.exit(); return update.fail("compiler failed to send terminating error_bundle", .{}); }, } @@ -1417,9 +1417,27 @@ fn spawnCompiler( const gpa = runner.gpa; const arena = runner.arena.allocator(); if (compiler.*) |*comp| { - try comp.exit(); + comp.deinit(); compiler.* = null; } + errdefer compiler.* = null; + + compiler.* = .{ + .runner = runner, + .allow_compiler_stderr = true, + .output_mode = output_mode, + .state = .idle, + .child = undefined, + .fw = undefined, + .mr_buffer = undefined, + .mr = undefined, + .client = undefined, + .target = target, + .emit_name = null, + .prog_node = .none, + .config = null, + }; + const comp = &compiler.*.?; var argv: std.ArrayList([]const u8) = .empty; defer argv.deinit(gpa); @@ -1431,20 +1449,19 @@ fn spawnCompiler( .Lib => "build-lib", }, "-target", - target.triple, + comp.target.triple, "--cache-dir", ".zig-cache", }); - switch (target.cache_mode) { + switch (comp.target.cache_mode) { .whole => {}, .incremental => try argv.append(gpa, "-fincremental"), } var path_buffer: [std.Io.Dir.max_path_bytes]u8 = undefined; - if (target.backend) |b| switch (b) { + if (comp.target.backend) |b| switch (b) { .sema => try argv.append(gpa, "-fno-emit-bin"), .selfhosted => try argv.append(gpa, "-fno-llvm"), .llvm => try argv.append(gpa, "-fllvm"), - .llvmir => try argv.append(gpa, "-ofmt=llvmir"), .cbe => try argv.append(gpa, "-ofmt=c"), } else try argv.appendSlice(gpa, &.{ "-I", path_buffer[0 .. (runner.args.lib_dir orelse return runner.fail("\"--lib=path/to/lib\" arg required with cbe", .{})) @@ -1452,12 +1469,12 @@ fn spawnCompiler( error.Canceled => |e| return e, else => |e| return runner.fail("unable to get lib path: {t}", .{e}), }] }); - switch (target.linker) { + switch (comp.target.linker) { .lld => try argv.appendSlice(gpa, &.{ "-flld", "-fno-new-linker" }), .old => try argv.appendSlice(gpa, &.{ "-fno-lld", "-fno-new-linker" }), .new => try argv.appendSlice(gpa, &.{ "-fno-lld", "-fnew-linker" }), } - switch (target.pic) { + switch (comp.target.pic) { .nopic => try argv.appendSlice(gpa, &.{ "-fno-PIC", "-fno-PIE" }), .pic => try argv.appendSlice(gpa, &.{ "-fPIC", "-fno-PIE" }), .pie => try argv.appendSlice(gpa, &.{ "-fPIC", "-fPIE" }), @@ -1466,6 +1483,7 @@ fn spawnCompiler( var need: usize = 1; var state: enum { positional, @"--name" } = .positional; var root_name: ?[]const u8 = null; + var emit: ?std.zig.EmitArtifact = .bin; while (true) { const done = if (args_r.fill(need)) false else |err| switch (err) { error.ReadFailed => |e| return e, @@ -1479,10 +1497,42 @@ fn spawnCompiler( switch (state) { .positional => if (std.mem.eql(u8, arg, "--name")) { state = .@"--name"; + } else if (std.mem.cutPrefix(u8, arg, "-ofmt=")) |ofmt| { + comp.target.resolved.ofmt = + std.meta.stringToEnum(std.Target.ObjectFormat, ofmt) orelse + return runner.fail("invalid object format {q}", .{ofmt}); } else if (std.mem.cutPrefix(u8, arg, "-M")) |module| { var module_name_it = std.mem.splitScalar(u8, module, '='); const module_name = module_name_it.next().?; root_name = root_name orelse module_name; + } else if (std.mem.eql(u8, arg, "-femit-asm")) { + emit = .@"asm"; + } else if (std.mem.eql(u8, arg, "-femit-bin")) { + emit = .bin; + } else if (std.mem.eql(u8, arg, "-femit-docs")) { + emit = .docs; + } else if (std.mem.eql(u8, arg, "-femit-h")) { + emit = .h; + } else if (std.mem.eql(u8, arg, "-femit-implib")) { + emit = .implib; + } else if (std.mem.eql(u8, arg, "-femit-llvm-bc")) { + emit = .llvm_bc; + } else if (std.mem.eql(u8, arg, "-femit-llvm-ir")) { + emit = .llvm_ir; + } else if (std.mem.eql(u8, arg, "-fno-emit-asm")) { + if (emit == .@"asm") emit = null; + } else if (std.mem.eql(u8, arg, "-fno-emit-bin")) { + if (emit == .bin) emit = null; + } else if (std.mem.eql(u8, arg, "-fno-emit-docs")) { + if (emit == .docs) emit = null; + } else if (std.mem.eql(u8, arg, "-fno-emit-h")) { + if (emit == .h) emit = null; + } else if (std.mem.eql(u8, arg, "-fno-emit-implib")) { + if (emit == .implib) emit = null; + } else if (std.mem.eql(u8, arg, "-fno-emit-llvm-bc")) { + if (emit == .llvm_bc) emit = null; + } else if (std.mem.eql(u8, arg, "-fno-emit-llvm-ir")) { + if (emit == .llvm_ir) emit = null; }, .@"--name" => { root_name = arg; @@ -1500,27 +1550,27 @@ fn spawnCompiler( } try argv.append(gpa, "--listen=-"); - const out_name = try std.zig.EmitArtifact.bin.cacheName(arena, .{ + comp.emit_name = if (emit) |e| try e.cacheName(arena, .{ .root_name = root_name orelse "root", - .cpu_arch = target.resolved.cpu.arch, - .os_tag = target.resolved.os.tag, - .ofmt = target.resolved.ofmt, - .abi = target.resolved.abi, + .cpu_arch = comp.target.resolved.cpu.arch, + .os_tag = comp.target.resolved.os.tag, + .ofmt = comp.target.resolved.ofmt, + .abi = comp.target.resolved.abi, .output_mode = output_mode, - }); + }) else null; var name_buffer: [std.Progress.Node.max_name_len]u8 = undefined; - const comp_prog_node = runner.prog_node.start(std.mem.print(&name_buffer, "compile {s}", .{ - out_name, + comp.prog_node = runner.prog_node.start(std.mem.print(&name_buffer, "compile {s}", .{ + comp.emit_name orelse root_name orelse "root", }) catch &name_buffer, 0); - errdefer comp_prog_node.end(); + errdefer comp.prog_node.end(); - const child = std.process.spawn(runner.io, .{ + comp.child = std.process.spawn(runner.io, .{ .exe = .{ .file = runner.args.zig_exe orelse return runner.fail("missing \"--zig=path/to/zig\" arg", .{}) }, .argv = argv.items, .cwd = .{ .dir = src_dir }, - .progress_node = comp_prog_node, + .progress_node = comp.prog_node, .stdin = .pipe, .stdout = .pipe, .stderr = .pipe, @@ -1529,31 +1579,14 @@ fn spawnCompiler( error.OperationUnsupported => return error.SkipTest, else => |e| return runner.fail("unable to spawn compiler: {t}", .{e}), }; - compiler.* = .{ - .runner = runner, - .prog_node = comp_prog_node, - .allow_compiler_stderr = true, - .output_mode = output_mode, - .state = .idle, - .child = child, - .fw = undefined, - .mr_buffer = undefined, - .mr = undefined, - .client = undefined, - .target = target, - .out_name = out_name, - .config = null, - }; - const comp = &compiler.*.?; - comp.fw = child.stdin.?.writerStreaming(runner.io, &.{}); + comp.fw = comp.child.stdin.?.writerStreaming(runner.io, &.{}); comp.mr.init(gpa, runner.io, comp.mr_buffer.toStreams(), &.{ - child.stdout.?, child.stderr.?, + comp.child.stdout.?, comp.child.stderr.?, }); comp.client = .{ .in = comp.mr.reader(0), .out = &comp.fw.interface }; } const Compiler = struct { runner: *Runner, - prog_node: std.Progress.Node, allow_compiler_stderr: bool, output_mode: std.lang.OutputMode, state: enum { idle, update }, @@ -1563,7 +1596,8 @@ const Compiler = struct { mr: std.Io.File.MultiReader, client: std.zig.Client, target: Compiler.Target, - out_name: []const u8, + emit_name: ?[]const u8, + prog_node: std.Progress.Node, config: ?std.zig.Server.Message.Config, const Target = struct { @@ -1586,8 +1620,6 @@ const Compiler = struct { /// Use the LLVM backend. /// Corresponds to `-fllvm -flld`. llvm, - /// Use the LLVM backend without libLLVM. - llvmir, /// Use the C backend. The output is compiled with `zig cc`. /// Corresponds to `-ofmt=c`. cbe, @@ -1598,6 +1630,12 @@ const Compiler = struct { const Pic = enum { nopic, pic, pie }; }; + fn deinit(comp: *Compiler) void { + comp.child.kill(comp.runner.io); + comp.prog_node.end(); + comp.prog_node = .none; + } + fn receiveMessage(comp: *Compiler) FailError!?struct { tag: std.zig.Server.Message.Tag, body: []const u8, @@ -1639,6 +1677,11 @@ const Compiler = struct { const arena = runner.arena.allocator(); const io = runner.io; const target = &comp.target.resolved; + const emit_name = switch (check) { + else => comp.emit_name orelse + return update.fail("unable to perform {t} check without emitted file", .{check}), + .errors => return, // expect no emitted file + }; const config = &comp.config.?; var path_buffer: [std.Io.Dir.max_path_bytes]u8 = undefined; @@ -1655,14 +1698,49 @@ const Compiler = struct { }), }; - var argv: std.ArrayList([]const u8) = .initBuffer(try arena.alloc([]const u8, 5 + 4)); + const emit_path = emit_path: { + const emit_dir_path = ".zig-cache" ++ std.Io.Dir.path.sep_str ++ + "o" ++ std.Io.Dir.path.sep_str ++ std.Build.Cache.binToHex(digest.*); + const emit_path = + try std.Io.Dir.path.join(arena, &.{ emit_dir_path, emit_name }); + break :emit_path switch (comp.target.backend.?) { + .sema => return, + .selfhosted, .llvm => emit_path, + .cbe => try comp.compileC(update.src_dir, emit_path), + }; + }; + + const emit_file = update.src_dir.openFile(io, emit_path, .{}) catch |err| switch (err) { + error.Canceled => |e| return e, + else => |e| return update.fail("unable to open {q}: {t}", .{ emit_path, e }), + }; + defer emit_file.close(io); + + var argv: std.ArrayList([]const u8) = try .initCapacity(arena, 5 + 4); var environ_map: std.process.Environ.Map = .init(gpa); defer environ_map.deinit(); try environ_map.putAll(&runner.environ_map); var script_buffer: [512]u8 = undefined; const script_path, const script_file, var script_fw = script: switch (check) { - .errors => return, - .stdout, .exit, .llvm => .{ undefined, null, undefined }, + .errors => unreachable, + .stdout, .exit => .{ undefined, null, undefined }, + .llvm => { + var emit_fr = emit_file.reader(io, &.{}); + const actual = emit_fr.interface.readAllocAll(arena, @intCast( + emit_fr.getSize() catch |err| switch (err) { + error.Canceled => |e| return e, + else => |e| return runner.fail("unable to get size of {q}: {t}", .{ emit_path, e }), + }, + )) catch |err| switch (switch (err) { + error.OutOfMemory => |e| return e, + error.EndOfStream => |e| e, + error.ReadFailed => emit_fr.err.?, + }) { + error.Canceled => |e| return e, + else => |e| return runner.fail("unable to read {q}: {t}", .{ emit_path, e }), + }; + return update.checkMatches("LLVM IR", expected, actual); + }, .gdb => { const script_path = tmp_dir_path ++ std.Io.Dir.path.sep_str ++ "gdb"; argv.appendSliceAssumeCapacity(&.{ "gdb", "--batch", "--command", script_path, "--args" }); @@ -1721,15 +1799,6 @@ const Compiler = struct { }; defer if (script_file) |file| file.close(io); - const out_dir_path = ".zig-cache" ++ std.Io.Dir.path.sep_str ++ - "o" ++ std.Io.Dir.path.sep_str ++ std.Build.Cache.binToHex(digest.*); - const out_path = try std.Io.Dir.path.join(arena, &.{ out_dir_path, comp.out_name }); - const bin_path = switch (comp.target.backend.?) { - .sema => return, - .selfhosted, .llvm, .llvmir => out_path, - .cbe => try comp.compileC(update.src_dir, out_path), - }; - const need_cross_libc = target.os.tag == .linux and config.flags.link_libc and config.flags.link_mode == .dynamic; const use_executor = use_executor: switch (std.zig.system.getExternalExecutor(io, target, .{ @@ -1796,7 +1865,7 @@ const Compiler = struct { break :use_executor true; } else continue :use_executor .bad_os_or_cpu, }; - argv.appendAssumeCapacity(bin_path); + argv.appendAssumeCapacity(emit_path); if (!runner.args.quiet) std.log.info("{f}", .{std.zig.SubprocessCommand{ .argv = argv.items, @@ -1815,41 +1884,19 @@ const Compiler = struct { var name_buffer: [std.Progress.Node.max_name_len]u8 = undefined; const run_prog_node = runner.prog_node.start(std.mem.print(&name_buffer, "run {s}", .{ - comp.out_name, + emit_name, }) catch &name_buffer, 0); defer run_prog_node.end(); - const bin_file = update.src_dir.openFile(io, bin_path, .{}) catch |err| switch (err) { - error.Canceled => |e| return e, - else => |e| return update.fail("unable to open {q}: {t}", .{ bin_path, e }), - }; - defer bin_file.close(io); const result = std.process.run(gpa, io, .{ .exe = exe: switch (check) { - .errors => unreachable, - .stdout, .exit => if (use_executor) .search else .{ .file = bin_file }, - .llvm => { - var bin_fr = bin_file.reader(io, &.{}); - const actual = bin_fr.interface.readAllocAll(arena, @intCast( - bin_fr.getSize() catch |err| switch (err) { - error.Canceled => |e| return e, - else => |e| return runner.fail("unable to get size of {q}: {t}", .{ bin_path, e }), - }, - )) catch |err| switch (switch (err) { - error.OutOfMemory => |e| return e, - error.EndOfStream => |e| e, - error.ReadFailed => bin_fr.err.?, - }) { - error.Canceled => |e| return e, - else => |e| return runner.fail("unable to read {q}: {t}", .{ bin_path, e }), - }; - return update.checkMatches("LLVM IR", expected, actual); - }, + .errors, .llvm => unreachable, + .stdout, .exit => if (use_executor) .search else .{ .file = emit_file }, .gdb, .lldb => { if (use_executor) { if (!runner.args.quiet) std.log.warn( "skipping debugging of {q} via executor for foreign target {q}", - .{ bin_path, comp.target.triple }, + .{ emit_path, comp.target.triple }, ); return; } @@ -1895,7 +1942,7 @@ const Compiler = struct { } orelse { if (!runner.args.quiet) std.log.warn( "skipping debugging of {q} because of missing \"--{t}=path/to/{[1]t}\" arg", - .{ bin_path, check }, + .{ emit_path, check }, ); return; } }; @@ -1909,11 +1956,11 @@ const Compiler = struct { // Chances are the foreign executor isn't available. Skip this evaluation. if (!runner.args.quiet) std.log.warn( "skipping execution of {q} via executor for foreign target {q}: {t}", - .{ bin_path, comp.target.triple, err }, + .{ emit_path, comp.target.triple, err }, ); return; } else return update.fail("unable to run the generated executable {q}: {t}", .{ - bin_path, err, + emit_path, err, }); defer { gpa.free(result.stdout); @@ -1925,7 +1972,7 @@ const Compiler = struct { .stdout => { if (code != 0) return update.fail( "generated executable {q} failed with code {d}", - .{ bin_path, code }, + .{ emit_path, code }, ); std.testing.expectEqualStrings( expected, @@ -1953,27 +2000,27 @@ const Compiler = struct { .gdb, .lldb => { if (code != debug_success) return update.fail( "debugging {q} failed with code {d}", - .{ bin_path, code }, + .{ emit_path, code }, ); try update.checkMatches("stdout", expected, result.stdout); }, }, .signal => |sig| return update.fail( "generated executable {q} terminated with signal {t}", - .{ bin_path, sig }, + .{ emit_path, sig }, ), .stopped => |sig| return update.fail( "generated executable {q} stopped with signal {t}", - .{ bin_path, sig }, + .{ emit_path, sig }, ), .unknown => return update.fail( "generated executable {q} terminated unexpectedly", - .{bin_path}, + .{emit_path}, ), } if (!use_executor and result.stderr.len > 0) { std.log.err("#update {q} generated executable {q} had unexpected stderr:\n{s}", .{ - update.name, bin_path, result.stderr, + update.name, emit_path, result.stderr, }); } } @@ -1999,6 +2046,7 @@ const Compiler = struct { error.ReadFailed => unreachable, // .fixed }; const comp = &compiler.?; + defer comp.deinit(); comp.client.serveBodylessMessage(.update) catch |err| switch (err) { error.WriteFailed => switch (comp.fw.err.?) { error.Canceled => |e| return e, @@ -2006,7 +2054,7 @@ const Compiler = struct { }, }; comp.state = .update; - var out_path: ?[]const u8 = null; + var emit_path: ?[]const u8 = null; while (try comp.receiveMessage()) |message| switch (message.tag) { else => {}, // Ignore other messages, .config => { @@ -2019,9 +2067,9 @@ const Compiler = struct { _ = body_r.takeStruct(std.zig.Server.Message.EmitDigest, .little) catch unreachable; const digest = body_r.takeArray(std.Build.Cache.bin_digest_len) catch unreachable; - const out_dir = ".zig-cache" ++ std.Io.Dir.path.sep_str ++ + const emit_dir = ".zig-cache" ++ std.Io.Dir.path.sep_str ++ "o" ++ std.Io.Dir.path.sep_str ++ std.Build.Cache.binToHex(digest.*); - out_path = try std.Io.Dir.path.join(arena, &.{ out_dir, comp.out_name }); + emit_path = try std.Io.Dir.path.join(arena, &.{ emit_dir, comp.emit_name.? }); }, .error_bundle => { const eb = std.zig.Server.allocErrorBundle( @@ -2040,7 +2088,7 @@ const Compiler = struct { }, }; try comp.exit(); - return out_path.?; + return emit_path.?; } fn exit(comp: *Compiler) FailError!void { @@ -2058,7 +2106,6 @@ const Compiler = struct { if (comp.client.in.bufferedLen() > 0) return runner.fail("unable to receive messages", .{}); const term = comp.child.wait(runner.io) catch |err| return runner.fail("child process failed: {t}", .{err}); - comp.prog_node.end(); switch (term) { .exited => |code| if (code != 0) return runner.fail("compiler failed with code {d}", .{code}), @@ -2309,8 +2356,8 @@ pub fn main(init: std.process.Init) (std.mem.Allocator.Error || std.Io.Cancelabl }; } - var inherit_dirs: std.ArrayList(std.Io.Dir) = .initBuffer(try arena.alloc(std.Io.Dir, 3)); - var inherit_files: std.ArrayList(std.Io.File) = .initBuffer(try arena.alloc(std.Io.File, 4)); + var inherit_dirs: std.ArrayList(std.Io.Dir) = try .initCapacity(arena, 3); + var inherit_files: std.ArrayList(std.Io.File) = try .initCapacity(arena, 4); inherit_files.appendSliceAssumeCapacity(&.{ args.test_file, args.zig_exe }); inherit_dirs.appendSliceAssumeCapacity(&.{ args.lib_dir, args.src_dir }); if (args.libc_runtimes_dir) |libc_runtimes_dir| inherit_dirs.appendAssumeCapacity(libc_runtimes_dir); diff --git a/test/llvm-ir/array_to_vector b/test/llvm-ir/array_to_vector deleted file mode 100644 index ab182e1284306a69018581765d41d99d4e45e893..0000000000000000000000000000000000000000 --- a/test/llvm-ir/array_to_vector +++ /dev/null @@ -1,38 +0,0 @@ -#obj { ---name test --Mroot=test.zig -#} - -#write test.zig { -export fn entry(arr: *const [16]u8) @Vector(16, u8) { - return arr.*; -} -#} -#update "one vector load" -#check llvm { -define #...<16 x i8> @test.entry(#...) #...{ -#... - %1 = alloca [16 x i8], align 1#... - %3 = load <16 x i8>, ptr %1, align 1#... - ret <16 x i8> %3#... -#} - -#write test.zig { -export fn entry(a: *@Vector(8, u8), b: *@Vector(8, u8), src: [*]const u8) void { - const q: @Vector(16, u8) = src[0..16].*; - a.* = @shuffle(u8, q, undefined, @Vector(8, i32){ 0, 1, 2, 3, 4, 5, 6, 7 }); - b.* = @shuffle(u8, q, undefined, @Vector(8, i32){ 7, 8, 9, 10, 11, 12, 13, 14 }); -} -#} -#update "feeding overlapping shuffles" -#check llvm { -define #...void @test.entry(ptr #...%0, ptr #...%1, #...) #...{ -#... - %11 = load <16 x i8>, ptr %#... - %12 = shufflevector <16 x i8> %11, #... - store <8 x i8> %12, ptr %0, align 8#... - %13 = shufflevector <16 x i8> %11, #... - store <8 x i8> %13, ptr %1, align 8#... - ret void#... -} -#} diff --git a/test/llvm-ir/dead_store b/test/llvm-ir/dead_store deleted file mode 100644 index 362b913db4c69597316b1d8bc3e0e82304ef6fc3..0000000000000000000000000000000000000000 --- a/test/llvm-ir/dead_store +++ /dev/null @@ -1,43 +0,0 @@ -#obj { ---name test --Mroot=test.zig -#} - -#write test.zig { -export fn entry(ptr: *volatile i16) void { - ptr.* = 123; - ptr.* = 321; -} -#} -#update "volatile" -#check llvm { -define #...@test.entry(ptr #...%0) #...{ -#...store volatile i16 123, ptr %0#... -#...store volatile i16 321, ptr %0#... -} - -#} - -#write test.zig { -export fn entry(ptr: *volatile i16) void { - entry2(ptr[0..1]); -} -fn entry2(slice: []volatile i16) void { - @setRuntimeSafety(false); - slice[0] = 123; - slice[0] = 321; -} -#} -#update "volatile slice" -#check llvm { -define #...@test.entry(#...) #...{ -#... -} - -#... -define #...@test.entry2(#...) #...{ -#...store volatile i16 123, ptr %#... -#...store volatile i16 321, ptr %#... -} - -#} diff --git a/test/llvm-ir/load_store_bool b/test/llvm-ir/load_store_bool deleted file mode 100644 index e38c45cfad468412e499a87dc42bbf9ae7844bc7..0000000000000000000000000000000000000000 --- a/test/llvm-ir/load_store_bool +++ /dev/null @@ -1,28 +0,0 @@ -#obj { ---name test --Mroot=test.zig -#} - -#write test.zig { -export fn foo(a: *bool, b: *align(2) bool) void { - const tmp = a.*; - a.* = b.*; - b.* = tmp; -} -#} -#update -#check llvm { -define #...void @test.foo(ptr #...%0, ptr #...%1) #...{ -#... - %5 = load i8, ptr %0, align 1#... - %6 = trunc nuw i8 %5 to i1#... - %8 = load i8, ptr %1, align 2#... - %9 = trunc nuw i8 %8 to i1#... - %10 = zext i1 %9 to i8#... - store i8 %10, ptr %0, align 1#... - %11 = zext i1 %6 to i8#... - store i8 %11, ptr %1, align 2#... - ret void#... -} - -#} diff --git a/test/llvm-ir/matrix.zon b/test/llvm-ir/matrix.zon deleted file mode 100644 index 4c810d784d3a445f913defa190d1c6e55a230b38..0000000000000000000000000000000000000000 --- a/test/llvm-ir/matrix.zon +++ /dev/null @@ -1,8 +0,0 @@ -.{ - .{ - .cache_mode = .whole, - .backend = .llvmir, - .linker = .old, - .pic = .pic, - }, -} diff --git a/test/llvm-ir/nonnull b/test/llvm-ir/nonnull deleted file mode 100644 index d3cb0546bdc83b6e3256d17ff0caed5f0a5232bd..0000000000000000000000000000000000000000 --- a/test/llvm-ir/nonnull +++ /dev/null @@ -1,30 +0,0 @@ -#obj { ---name test --Mroot=test.zig -#} - -#write test.zig { -export fn entry(ptr: *i16) i16 { - return ptr.*; -} -#} -#update "store" -#check llvm { -define #...@test.entry(ptr #...nonnull #...%0) #...{ -#...load i16, ptr %0#... -} - -#} - -#write test.zig { -export fn entry(ptr: *i16) void { - ptr.* = 42; -} -#} -#update "load" -#check llvm { -define #...@test.entry(ptr #...nonnull #...%0) #...{ -#...store i16 42, ptr %0#... -} - -#} diff --git a/test/llvm-ir/allowzero b/test/llvm/allowzero similarity index 55% rename from test/llvm-ir/allowzero rename to test/llvm/allowzero index e83cf1faf438b237f1d012a691d31998b4d437e3..3883eb84115c94f32695c11c4fec99d8924c3497 100644 --- a/test/llvm-ir/allowzero +++ b/test/llvm/allowzero @@ -1,5 +1,31 @@ +#skip amdgcn-amdhsa-none-baseline-whole-llvm-lld-pic +#skip amdgcn-amdpal-none-baseline-whole-llvm-lld-pic +#skip amdgcn-mesa3d-none-baseline-whole-llvm-lld-pic + +#skip bpfeb-freestanding-none-baseline-whole-llvm-lld-pic + +#skip bpfel-freestanding-none-baseline-whole-llvm-lld-pic + +#skip nvptx-cuda-none-baseline-whole-llvm-lld-pic +#skip nvptx-nvcl-none-baseline-whole-llvm-lld-pic + +#skip nvptx64-cuda-none-baseline-whole-llvm-lld-pic +#skip nvptx64-nvcl-none-baseline-whole-llvm-lld-pic + +#skip spirv32-opencl-none-baseline-whole-llvm-lld-pic +#skip spirv32-opengl-none-baseline-whole-llvm-lld-pic +#skip spirv32-vulkan-none-baseline-whole-llvm-lld-pic + +#skip spirv64-amdhsa-none-baseline-whole-llvm-lld-pic +#skip spirv64-opencl-none-baseline-whole-llvm-lld-pic +#skip spirv64-vulkan-none-baseline-whole-llvm-lld-pic + +#skip x86_64-linux-gnux32-baseline-whole-llvm-new-pic +#skip x86_64-linux-muslx32-baseline-whole-llvm-new-pic +#skip x86_64-linux-x32-baseline-whole-llvm-new-pic + #obj { ---name test +--name test -fno-lld -fno-new-linker -ofmt=llvmir -Mroot=test.zig #} diff --git a/test/llvm/array_to_vector b/test/llvm/array_to_vector new file mode 100644 index 0000000000000000000000000000000000000000..db4316af54b7fcd71b1f28fedd50aff961831252 --- /dev/null +++ b/test/llvm/array_to_vector @@ -0,0 +1,109 @@ +#skip amdgcn-amdhsa-none-baseline-whole-llvm-lld-pic +#skip amdgcn-amdpal-none-baseline-whole-llvm-lld-pic +#skip amdgcn-mesa3d-none-baseline-whole-llvm-lld-pic + +#skip bpfeb-freestanding-none-baseline-whole-llvm-lld-pic + +#skip bpfel-freestanding-none-baseline-whole-llvm-lld-pic + +#skip loongarch32-freestanding-none-baseline-whole-llvm-lld-pic +#skip loongarch32-linux-gnu-baseline-whole-llvm-lld-pic +#skip loongarch32-linux-gnuf32-baseline-whole-llvm-lld-pic +#skip loongarch32-linux-gnusf-baseline-whole-llvm-lld-pic +#skip loongarch32-linux-musl-baseline-whole-llvm-lld-pic +#skip loongarch32-linux-muslf32-baseline-whole-llvm-lld-pic +#skip loongarch32-linux-muslsf-baseline-whole-llvm-lld-pic +#skip loongarch32-linux-none-baseline-whole-llvm-lld-pic +#skip loongarch32-uefi-none-baseline-whole-llvm-lld-pic + +#skip loongarch64-freestanding-none-baseline-whole-llvm-lld-pic +#skip loongarch64-linux-gnu-baseline-whole-llvm-lld-pic +#skip loongarch64-linux-gnuf32-baseline-whole-llvm-lld-pic +#skip loongarch64-linux-gnusf-baseline-whole-llvm-lld-pic +#skip loongarch64-linux-musl-baseline-whole-llvm-lld-pic +#skip loongarch64-linux-muslf32-baseline-whole-llvm-lld-pic +#skip loongarch64-linux-muslsf-baseline-whole-llvm-lld-pic +#skip loongarch64-linux-none-baseline-whole-llvm-lld-pic +#skip loongarch64-uefi-none-baseline-whole-llvm-lld-pic + +#skip nvptx-cuda-none-baseline-whole-llvm-lld-pic +#skip nvptx-nvcl-none-baseline-whole-llvm-lld-pic + +#skip nvptx64-cuda-none-baseline-whole-llvm-lld-pic +#skip nvptx64-nvcl-none-baseline-whole-llvm-lld-pic + +#skip riscv32-freestanding-none-baseline-whole-llvm-lld-pic +#skip riscv32-linux-gnu-baseline-whole-llvm-lld-pic +#skip riscv32-linux-musl-baseline-whole-llvm-lld-pic +#skip riscv32-linux-none-baseline-whole-llvm-lld-pic +#skip riscv32-netbsd-none-baseline-whole-llvm-lld-pic +#skip riscv32-rtems-none-baseline-whole-llvm-lld-pic +#skip riscv32-uefi-none-baseline-whole-llvm-lld-pic +#skip riscv32be-freestanding-none-baseline-whole-llvm-lld-pic + +#skip riscv64-freebsd-none-baseline-whole-llvm-lld-pic +#skip riscv64-freestanding-none-baseline-whole-llvm-lld-pic +#skip riscv64-fuchsia-none-baseline-whole-llvm-lld-pic +#skip riscv64-haiku-none-baseline-whole-llvm-lld-pic +#skip riscv64-hurd-gnu-baseline-whole-llvm-lld-pic +#skip riscv64-linux-android-baseline-whole-llvm-lld-pic +#skip riscv64-linux-gnu-baseline-whole-llvm-lld-pic +#skip riscv64-linux-musl-baseline-whole-llvm-lld-pic +#skip riscv64-linux-none-baseline-whole-llvm-lld-pic +#skip riscv64-netbsd-none-baseline-whole-llvm-lld-pic +#skip riscv64-openbsd-none-baseline-whole-llvm-lld-pic +#skip riscv64-rtems-none-baseline-whole-llvm-lld-pic +#skip riscv64-serenity-none-baseline-whole-llvm-lld-pic +#skip riscv64-uefi-none-baseline-whole-llvm-lld-pic +#skip riscv64be-freestanding-none-baseline-whole-llvm-lld-pic + +#skip spirv32-opencl-none-baseline-whole-llvm-lld-pic +#skip spirv32-opengl-none-baseline-whole-llvm-lld-pic +#skip spirv32-vulkan-none-baseline-whole-llvm-lld-pic + +#skip spirv64-amdhsa-none-baseline-whole-llvm-lld-pic +#skip spirv64-opencl-none-baseline-whole-llvm-lld-pic +#skip spirv64-vulkan-none-baseline-whole-llvm-lld-pic + +#skip x86_64-linux-gnux32-baseline-whole-llvm-new-pic +#skip x86_64-linux-muslx32-baseline-whole-llvm-new-pic +#skip x86_64-linux-x32-baseline-whole-llvm-new-pic + +#obj { +--name test -fno-lld -fno-new-linker -ofmt=llvmir +-Mroot=test.zig +#} + +#write test.zig { +export fn entry(arr: *const [16]u8) @Vector(16, u8) { + return arr.*; +} +#} +#update "one vector load" +#check llvm { +define #...<16 x i8> @test.entry(#...) #...{ +#... + %1 = alloca [16 x i8], align 1#... + %3 = load <16 x i8>, ptr %1, align 1#... + ret <16 x i8> %3#... +#} + +#write test.zig { +export fn entry(a: *@Vector(8, u8), b: *@Vector(8, u8), src: [*]const u8) void { + const q: @Vector(16, u8) = src[0..16].*; + a.* = @shuffle(u8, q, undefined, @Vector(8, i32){ 0, 1, 2, 3, 4, 5, 6, 7 }); + b.* = @shuffle(u8, q, undefined, @Vector(8, i32){ 7, 8, 9, 10, 11, 12, 13, 14 }); +} +#} +#update "feeding overlapping shuffles" +#check llvm { +define #...void @test.entry(ptr #...%0, ptr #...%1, #...) #...{ +#... + %11 = load <16 x i8>, ptr %#... + %12 = shufflevector <16 x i8> %11, #... + store <8 x i8> %12, ptr %0, align 8#... + %13 = shufflevector <16 x i8> %11, #... + store <8 x i8> %13, ptr %1, align 8#... + ret void#... +} +#} diff --git a/test/llvm/dead_store b/test/llvm/dead_store new file mode 100644 index 0000000000000000000000000000000000000000..ec59117ad730d0cdc64af2411ab2ac0275e6c287 --- /dev/null +++ b/test/llvm/dead_store @@ -0,0 +1,65 @@ +#skip amdgcn-amdhsa-none-baseline-whole-llvm-lld-pic +#skip amdgcn-amdpal-none-baseline-whole-llvm-lld-pic +#skip amdgcn-mesa3d-none-baseline-whole-llvm-lld-pic + +#skip nvptx-cuda-none-baseline-whole-llvm-lld-pic +#skip nvptx-nvcl-none-baseline-whole-llvm-lld-pic + +#skip nvptx64-cuda-none-baseline-whole-llvm-lld-pic +#skip nvptx64-nvcl-none-baseline-whole-llvm-lld-pic + +#skip spirv32-opencl-none-baseline-whole-llvm-lld-pic +#skip spirv32-opengl-none-baseline-whole-llvm-lld-pic +#skip spirv32-vulkan-none-baseline-whole-llvm-lld-pic + +#skip spirv64-amdhsa-none-baseline-whole-llvm-lld-pic +#skip spirv64-opencl-none-baseline-whole-llvm-lld-pic +#skip spirv64-vulkan-none-baseline-whole-llvm-lld-pic + +#skip x86_64-linux-gnux32-baseline-whole-llvm-new-pic +#skip x86_64-linux-muslx32-baseline-whole-llvm-new-pic +#skip x86_64-linux-x32-baseline-whole-llvm-new-pic + +#obj { +--name test -fno-lld -fno-new-linker -ofmt=llvmir +-Mroot=test.zig +#} + +#write test.zig { +export fn entry(ptr: *volatile i16) void { + ptr.* = 123; + ptr.* = 321; +} +#} +#update "volatile" +#check llvm { +define #...@test.entry(ptr #...%0) #...{ +#...store volatile i16 123, ptr %0#... +#...store volatile i16 321, ptr %0#... +} + +#} + +#write test.zig { +export fn entry(ptr: *volatile i16) void { + entry2(ptr[0..1]); +} +fn entry2(slice: []volatile i16) void { + @setRuntimeSafety(false); + slice[0] = 123; + slice[0] = 321; +} +#} +#update "volatile slice" +#check llvm { +define #...@test.entry(#...) #...{ +#... +} + +#... +define #...@test.entry2(#...) #...{ +#...store volatile i16 123, ptr %#... +#...store volatile i16 321, ptr %#... +} + +#} diff --git a/test/llvm-targets/empty_analyze b/test/llvm/empty_analyze similarity index 96% rename from test/llvm-targets/empty_analyze rename to test/llvm/empty_analyze index c6fdbea1129cc1a7ec6107a812a899d99d46817a..83f8b9adfad2a1b79ec2adf06739cab3cee88900 100644 --- a/test/llvm-targets/empty_analyze +++ b/test/llvm/empty_analyze @@ -40,11 +40,11 @@ #skip spirv64-vulkan-none-baseline-whole-llvm-lld-pic #obj { ---name llvm_targets --Mroot=analyze.zig +--name test +-Mroot=test.zig -fno-emit-asm -fno-emit-bin #} -#write analyze.zig +#write test.zig #update #check errors diff --git a/test/llvm-targets/empty_assembly b/test/llvm/empty_assembly similarity index 96% rename from test/llvm-targets/empty_assembly rename to test/llvm/empty_assembly index e140e4f6fcfa0108147f877626e267311203dbd6..30a58733d045c6e1c9c6af10fbf8aae192e75754 100644 --- a/test/llvm-targets/empty_assembly +++ b/test/llvm/empty_assembly @@ -45,11 +45,11 @@ #skip xtensa-linux-none-baseline-whole-llvm-lld-pic #obj { ---name llvm_targets --Mroot=assembly.zig +--name test +-Mroot=test.zig -femit-asm -fno-emit-bin #} -#write assembly.zig +#write test.zig #update #check errors diff --git a/test/llvm-targets/empty_object b/test/llvm/empty_object similarity index 97% rename from test/llvm-targets/empty_object rename to test/llvm/empty_object index 6d52ba2d3a9ee515e453f9d13b7bdb1249615391..b42e86be09bd48d78ae38accc26574b3403981ac 100644 --- a/test/llvm-targets/empty_object +++ b/test/llvm/empty_object @@ -57,11 +57,11 @@ #skip xtensa-linux-none-baseline-whole-llvm-lld-pic #obj { ---name llvm_targets --Mroot=object.zig +--name test +-Mroot=test.zig -fno-emit-asm -femit-bin #} -#write object.zig +#write test.zig #update #check errors diff --git a/test/llvm/load_store_bool b/test/llvm/load_store_bool new file mode 100644 index 0000000000000000000000000000000000000000..b59421e5cf1b3b31fa26570e02c83dedc30aaeac --- /dev/null +++ b/test/llvm/load_store_bool @@ -0,0 +1,95 @@ +#skip amdgcn-amdhsa-none-baseline-whole-llvm-lld-pic +#skip amdgcn-amdpal-none-baseline-whole-llvm-lld-pic +#skip amdgcn-mesa3d-none-baseline-whole-llvm-lld-pic + +#skip bpfeb-freestanding-none-baseline-whole-llvm-lld-pic + +#skip bpfel-freestanding-none-baseline-whole-llvm-lld-pic + +#skip loongarch32-freestanding-none-baseline-whole-llvm-lld-pic +#skip loongarch32-linux-gnu-baseline-whole-llvm-lld-pic +#skip loongarch32-linux-gnuf32-baseline-whole-llvm-lld-pic +#skip loongarch32-linux-gnusf-baseline-whole-llvm-lld-pic +#skip loongarch32-linux-musl-baseline-whole-llvm-lld-pic +#skip loongarch32-linux-muslf32-baseline-whole-llvm-lld-pic +#skip loongarch32-linux-muslsf-baseline-whole-llvm-lld-pic +#skip loongarch32-linux-none-baseline-whole-llvm-lld-pic +#skip loongarch32-uefi-none-baseline-whole-llvm-lld-pic + +#skip loongarch64-freestanding-none-baseline-whole-llvm-lld-pic +#skip loongarch64-linux-gnu-baseline-whole-llvm-lld-pic +#skip loongarch64-linux-gnuf32-baseline-whole-llvm-lld-pic +#skip loongarch64-linux-gnu-baseline-whole-llvm-lld-pic +#skip loongarch64-linux-gnuf32-baseline-whole-llvm-lld-pic +#skip loongarch64-linux-gnusf-baseline-whole-llvm-lld-pic +#skip loongarch64-linux-musl-baseline-whole-llvm-lld-pic +#skip loongarch64-linux-muslf32-baseline-whole-llvm-lld-pic +#skip loongarch64-linux-muslsf-baseline-whole-llvm-lld-pic +#skip loongarch64-linux-none-baseline-whole-llvm-lld-pic +#skip loongarch64-uefi-none-baseline-whole-llvm-lld-pic + +#skip nvptx-cuda-none-baseline-whole-llvm-lld-pic +#skip nvptx-nvcl-none-baseline-whole-llvm-lld-pic + +#skip nvptx64-cuda-none-baseline-whole-llvm-lld-pic +#skip nvptx64-nvcl-none-baseline-whole-llvm-lld-pic + +#skip riscv32-freestanding-none-baseline-whole-llvm-lld-pic +#skip riscv32-linux-gnu-baseline-whole-llvm-lld-pic +#skip riscv32-linux-musl-baseline-whole-llvm-lld-pic +#skip riscv32-linux-none-baseline-whole-llvm-lld-pic +#skip riscv32-netbsd-none-baseline-whole-llvm-lld-pic +#skip riscv32-rtems-none-baseline-whole-llvm-lld-pic +#skip riscv32-uefi-none-baseline-whole-llvm-lld-pic + +#skip riscv32be-freestanding-none-baseline-whole-llvm-lld-pic + +#skip riscv64-freebsd-none-baseline-whole-llvm-lld-pic +#skip riscv64-freestanding-none-baseline-whole-llvm-lld-pic +#skip riscv64-fuchsia-none-baseline-whole-llvm-lld-pic +#skip riscv64-haiku-none-baseline-whole-llvm-lld-pic +#skip riscv64-hurd-gnu-baseline-whole-llvm-lld-pic +#skip riscv64-linux-android-baseline-whole-llvm-lld-pic +#skip riscv64-linux-gnu-baseline-whole-llvm-lld-pic +#skip riscv64-linux-musl-baseline-whole-llvm-lld-pic +#skip riscv64-linux-none-baseline-whole-llvm-lld-pic +#skip riscv64-netbsd-none-baseline-whole-llvm-lld-pic +#skip riscv64-openbsd-none-baseline-whole-llvm-lld-pic +#skip riscv64-rtems-none-baseline-whole-llvm-lld-pic +#skip riscv64-serenity-none-baseline-whole-llvm-lld-pic +#skip riscv64-uefi-none-baseline-whole-llvm-lld-pic + +#skip riscv64be-freestanding-none-baseline-whole-llvm-lld-pic + +#skip x86_64-linux-gnux32-baseline-whole-llvm-new-pic +#skip x86_64-linux-muslx32-baseline-whole-llvm-new-pic +#skip x86_64-linux-x32-baseline-whole-llvm-new-pic + +#obj { +--name test -fno-lld -fno-new-linker -ofmt=llvmir +-Mroot=test.zig +#} + +#write test.zig { +export fn foo(a: *bool, b: *align(2) bool) void { + const tmp = a.*; + a.* = b.*; + b.* = tmp; +} +#} +#update +#check llvm { +define #...void @test.foo(ptr #...%0, ptr #...%1) #...{ +#... + %5 = load i8, ptr %0, align 1#... + %6 = trunc nuw i8 %5 to i1#... + %8 = load i8, ptr %1, align 2#... + %9 = trunc nuw i8 %8 to i1#... + %10 = zext i1 %9 to i8#... + store i8 %10, ptr %0, align 1#... + %11 = zext i1 %6 to i8#... + store i8 %11, ptr %1, align 2#... + ret void#... +} + +#} diff --git a/test/llvm-targets/matrix.zon b/test/llvm/matrix.zon similarity index 98% rename from test/llvm-targets/matrix.zon rename to test/llvm/matrix.zon index a3ec7955d459ec1a2493db0a647731bf488b2eca..8dafd5efada10939b1ca29d4f9d16f166907b03c 100644 --- a/test/llvm-targets/matrix.zon +++ b/test/llvm/matrix.zon @@ -250,12 +250,12 @@ .{ .cpu = .{ .sparc = .{} }, .os = .{ .netbsd = .{} }, .abi = .{ .none = .{} }, .cache_mode = .whole, .backend = .llvm, .linker = .lld, .pic = .pic }, .{ .cpu = .{ .sparc = .{} }, .os = .{ .rtems = .{} }, .abi = .{ .none = .{} }, .cache_mode = .whole, .backend = .llvm, .linker = .lld, .pic = .pic }, - .{ .cpu = .{ .sparc64 = .{} }, .os = .{ .freestanding = .{} }, .abi = .{ .none = .{} }, .cache_mode = .whole, .backend = .llvm, .linker = .lld, .pic = .pic }, - .{ .cpu = .{ .sparc64 = .{} }, .os = .{ .linux = .{} }, .abi = .{ .gnu = .{} }, .cache_mode = .whole, .backend = .llvm, .linker = .lld, .pic = .pic }, - .{ .cpu = .{ .sparc64 = .{} }, .os = .{ .linux = .{} }, .abi = .{ .none = .{} }, .cache_mode = .whole, .backend = .llvm, .linker = .lld, .pic = .pic }, - .{ .cpu = .{ .sparc64 = .{} }, .os = .{ .netbsd = .{} }, .abi = .{ .none = .{} }, .cache_mode = .whole, .backend = .llvm, .linker = .lld, .pic = .pic }, - .{ .cpu = .{ .sparc64 = .{} }, .os = .{ .openbsd = .{} }, .abi = .{ .none = .{} }, .cache_mode = .whole, .backend = .llvm, .linker = .lld, .pic = .pic }, - .{ .cpu = .{ .sparc64 = .{} }, .os = .{ .rtems = .{} }, .abi = .{ .none = .{} }, .cache_mode = .whole, .backend = .llvm, .linker = .lld, .pic = .pic }, + .{ .cpu = .{ .sparc64 = .{} }, .os = .{ .freestanding = .{} }, .abi = .{ .none = .{} }, .cache_mode = .whole, .backend = .llvm, .linker = .new, .pic = .pic }, + .{ .cpu = .{ .sparc64 = .{} }, .os = .{ .linux = .{} }, .abi = .{ .gnu = .{} }, .cache_mode = .whole, .backend = .llvm, .linker = .new, .pic = .pic }, + .{ .cpu = .{ .sparc64 = .{} }, .os = .{ .linux = .{} }, .abi = .{ .none = .{} }, .cache_mode = .whole, .backend = .llvm, .linker = .new, .pic = .pic }, + .{ .cpu = .{ .sparc64 = .{} }, .os = .{ .netbsd = .{} }, .abi = .{ .none = .{} }, .cache_mode = .whole, .backend = .llvm, .linker = .new, .pic = .pic }, + .{ .cpu = .{ .sparc64 = .{} }, .os = .{ .openbsd = .{} }, .abi = .{ .none = .{} }, .cache_mode = .whole, .backend = .llvm, .linker = .new, .pic = .pic }, + .{ .cpu = .{ .sparc64 = .{} }, .os = .{ .rtems = .{} }, .abi = .{ .none = .{} }, .cache_mode = .whole, .backend = .llvm, .linker = .new, .pic = .pic }, .{ .cpu = .{ .spirv32 = .{} }, .os = .{ .opencl = .{} }, .abi = .{ .none = .{} }, .cache_mode = .whole, .backend = .llvm, .linker = .lld, .pic = .pic }, .{ .cpu = .{ .spirv32 = .{} }, .os = .{ .opengl = .{} }, .abi = .{ .none = .{} }, .cache_mode = .whole, .backend = .llvm, .linker = .lld, .pic = .pic }, @@ -316,31 +316,31 @@ .{ .cpu = .{ .x86 = .{} }, .os = .{ .windows = .{} }, .abi = .{ .itanium = .{} }, .cache_mode = .whole, .backend = .llvm, .linker = .lld, .pic = .pic }, .{ .cpu = .{ .x86 = .{} }, .os = .{ .windows = .{} }, .abi = .{ .msvc = .{} }, .cache_mode = .whole, .backend = .llvm, .linker = .lld, .pic = .pic }, - .{ .cpu = .{ .x86_64 = .{} }, .os = .{ .freebsd = .{} }, .abi = .{ .none = .{} }, .cache_mode = .whole, .backend = .llvm, .linker = .lld, .pic = .pic }, - .{ .cpu = .{ .x86_64 = .{} }, .os = .{ .freestanding = .{} }, .abi = .{ .none = .{} }, .cache_mode = .whole, .backend = .llvm, .linker = .lld, .pic = .pic }, - .{ .cpu = .{ .x86_64 = .{ .features = .{ .add = .{.soft_float}, .remove = .{ .mmx, .sse, .sse2, .avx, .avx2 } } } }, .os = .{ .freestanding = .{} }, .abi = .{ .none = .{} }, .cache_mode = .whole, .backend = .llvm, .linker = .lld, .pic = .pic }, - .{ .cpu = .{ .x86_64 = .{} }, .os = .{ .fuchsia = .{} }, .abi = .{ .none = .{} }, .cache_mode = .whole, .backend = .llvm, .linker = .lld, .pic = .pic }, - .{ .cpu = .{ .x86_64 = .{} }, .os = .{ .dragonfly = .{} }, .abi = .{ .none = .{} }, .cache_mode = .whole, .backend = .llvm, .linker = .lld, .pic = .pic }, + .{ .cpu = .{ .x86_64 = .{} }, .os = .{ .freebsd = .{} }, .abi = .{ .none = .{} }, .cache_mode = .whole, .backend = .llvm, .linker = .new, .pic = .pic }, + .{ .cpu = .{ .x86_64 = .{} }, .os = .{ .freestanding = .{} }, .abi = .{ .none = .{} }, .cache_mode = .whole, .backend = .llvm, .linker = .new, .pic = .pic }, + .{ .cpu = .{ .x86_64 = .{ .features = .{ .add = .{.soft_float}, .remove = .{ .mmx, .sse, .sse2, .avx, .avx2 } } } }, .os = .{ .freestanding = .{} }, .abi = .{ .none = .{} }, .cache_mode = .whole, .backend = .llvm, .linker = .new, .pic = .pic }, + .{ .cpu = .{ .x86_64 = .{} }, .os = .{ .fuchsia = .{} }, .abi = .{ .none = .{} }, .cache_mode = .whole, .backend = .llvm, .linker = .new, .pic = .pic }, + .{ .cpu = .{ .x86_64 = .{} }, .os = .{ .dragonfly = .{} }, .abi = .{ .none = .{} }, .cache_mode = .whole, .backend = .llvm, .linker = .new, .pic = .pic }, .{ .cpu = .{ .x86_64 = .{} }, .os = .{ .driverkit = .{} }, .abi = .{ .none = .{} }, .cache_mode = .whole, .backend = .llvm, .linker = .old, .pic = .pic }, - .{ .cpu = .{ .x86_64 = .{} }, .os = .{ .haiku = .{} }, .abi = .{ .none = .{} }, .cache_mode = .whole, .backend = .llvm, .linker = .lld, .pic = .pic }, - .{ .cpu = .{ .x86_64 = .{} }, .os = .{ .hurd = .{} }, .abi = .{ .gnu = .{} }, .cache_mode = .whole, .backend = .llvm, .linker = .lld, .pic = .pic }, - .{ .cpu = .{ .x86_64 = .{} }, .os = .{ .illumos = .{} }, .abi = .{ .none = .{} }, .cache_mode = .whole, .backend = .llvm, .linker = .lld, .pic = .pic }, - .{ .cpu = .{ .x86_64 = .{} }, .os = .{ .linux = .{} }, .abi = .{ .android = .{} }, .cache_mode = .whole, .backend = .llvm, .linker = .lld, .pic = .pic }, - .{ .cpu = .{ .x86_64 = .{} }, .os = .{ .linux = .{} }, .abi = .{ .gnu = .{} }, .cache_mode = .whole, .backend = .llvm, .linker = .lld, .pic = .pic }, - .{ .cpu = .{ .x86_64 = .{} }, .os = .{ .linux = .{} }, .abi = .{ .gnux32 = .{} }, .cache_mode = .whole, .backend = .llvm, .linker = .lld, .pic = .pic }, - .{ .cpu = .{ .x86_64 = .{} }, .os = .{ .linux = .{} }, .abi = .{ .musl = .{} }, .cache_mode = .whole, .backend = .llvm, .linker = .lld, .pic = .pic }, - .{ .cpu = .{ .x86_64 = .{} }, .os = .{ .linux = .{} }, .abi = .{ .muslx32 = .{} }, .cache_mode = .whole, .backend = .llvm, .linker = .lld, .pic = .pic }, - .{ .cpu = .{ .x86_64 = .{} }, .os = .{ .linux = .{} }, .abi = .{ .none = .{} }, .cache_mode = .whole, .backend = .llvm, .linker = .lld, .pic = .pic }, - .{ .cpu = .{ .x86_64 = .{} }, .os = .{ .linux = .{} }, .abi = .{ .ohos = .{} }, .cache_mode = .whole, .backend = .llvm, .linker = .lld, .pic = .pic }, - .{ .cpu = .{ .x86_64 = .{} }, .os = .{ .linux = .{} }, .abi = .{ .x32 = .{} }, .cache_mode = .whole, .backend = .llvm, .linker = .lld, .pic = .pic }, + .{ .cpu = .{ .x86_64 = .{} }, .os = .{ .haiku = .{} }, .abi = .{ .none = .{} }, .cache_mode = .whole, .backend = .llvm, .linker = .new, .pic = .pic }, + .{ .cpu = .{ .x86_64 = .{} }, .os = .{ .hurd = .{} }, .abi = .{ .gnu = .{} }, .cache_mode = .whole, .backend = .llvm, .linker = .new, .pic = .pic }, + .{ .cpu = .{ .x86_64 = .{} }, .os = .{ .illumos = .{} }, .abi = .{ .none = .{} }, .cache_mode = .whole, .backend = .llvm, .linker = .new, .pic = .pic }, + .{ .cpu = .{ .x86_64 = .{} }, .os = .{ .linux = .{} }, .abi = .{ .android = .{} }, .cache_mode = .whole, .backend = .llvm, .linker = .new, .pic = .pic }, + .{ .cpu = .{ .x86_64 = .{} }, .os = .{ .linux = .{} }, .abi = .{ .gnu = .{} }, .cache_mode = .whole, .backend = .llvm, .linker = .new, .pic = .pic }, + .{ .cpu = .{ .x86_64 = .{} }, .os = .{ .linux = .{} }, .abi = .{ .gnux32 = .{} }, .cache_mode = .whole, .backend = .llvm, .linker = .new, .pic = .pic }, + .{ .cpu = .{ .x86_64 = .{} }, .os = .{ .linux = .{} }, .abi = .{ .musl = .{} }, .cache_mode = .whole, .backend = .llvm, .linker = .new, .pic = .pic }, + .{ .cpu = .{ .x86_64 = .{} }, .os = .{ .linux = .{} }, .abi = .{ .muslx32 = .{} }, .cache_mode = .whole, .backend = .llvm, .linker = .new, .pic = .pic }, + .{ .cpu = .{ .x86_64 = .{} }, .os = .{ .linux = .{} }, .abi = .{ .none = .{} }, .cache_mode = .whole, .backend = .llvm, .linker = .new, .pic = .pic }, + .{ .cpu = .{ .x86_64 = .{} }, .os = .{ .linux = .{} }, .abi = .{ .ohos = .{} }, .cache_mode = .whole, .backend = .llvm, .linker = .new, .pic = .pic }, + .{ .cpu = .{ .x86_64 = .{} }, .os = .{ .linux = .{} }, .abi = .{ .x32 = .{} }, .cache_mode = .whole, .backend = .llvm, .linker = .new, .pic = .pic }, .{ .cpu = .{ .x86_64 = .{} }, .os = .{ .maccatalyst = .{} }, .abi = .{ .none = .{} }, .cache_mode = .whole, .backend = .llvm, .linker = .old, .pic = .pic }, .{ .cpu = .{ .x86_64 = .{} }, .os = .{ .macos = .{} }, .abi = .{ .none = .{} }, .cache_mode = .whole, .backend = .llvm, .linker = .old, .pic = .pic }, - .{ .cpu = .{ .x86_64 = .{} }, .os = .{ .netbsd = .{} }, .abi = .{ .none = .{} }, .cache_mode = .whole, .backend = .llvm, .linker = .lld, .pic = .pic }, - .{ .cpu = .{ .x86_64 = .{} }, .os = .{ .openbsd = .{} }, .abi = .{ .none = .{} }, .cache_mode = .whole, .backend = .llvm, .linker = .lld, .pic = .pic }, - .{ .cpu = .{ .x86_64 = .{} }, .os = .{ .ps4 = .{} }, .abi = .{ .none = .{} }, .cache_mode = .whole, .backend = .llvm, .linker = .lld, .pic = .pic }, - .{ .cpu = .{ .x86_64 = .{} }, .os = .{ .ps5 = .{} }, .abi = .{ .none = .{} }, .cache_mode = .whole, .backend = .llvm, .linker = .lld, .pic = .pic }, - .{ .cpu = .{ .x86_64 = .{} }, .os = .{ .rtems = .{} }, .abi = .{ .none = .{} }, .cache_mode = .whole, .backend = .llvm, .linker = .lld, .pic = .pic }, - .{ .cpu = .{ .x86_64 = .{} }, .os = .{ .serenity = .{} }, .abi = .{ .none = .{} }, .cache_mode = .whole, .backend = .llvm, .linker = .lld, .pic = .pic }, + .{ .cpu = .{ .x86_64 = .{} }, .os = .{ .netbsd = .{} }, .abi = .{ .none = .{} }, .cache_mode = .whole, .backend = .llvm, .linker = .new, .pic = .pic }, + .{ .cpu = .{ .x86_64 = .{} }, .os = .{ .openbsd = .{} }, .abi = .{ .none = .{} }, .cache_mode = .whole, .backend = .llvm, .linker = .new, .pic = .pic }, + .{ .cpu = .{ .x86_64 = .{} }, .os = .{ .ps4 = .{} }, .abi = .{ .none = .{} }, .cache_mode = .whole, .backend = .llvm, .linker = .new, .pic = .pic }, + .{ .cpu = .{ .x86_64 = .{} }, .os = .{ .ps5 = .{} }, .abi = .{ .none = .{} }, .cache_mode = .whole, .backend = .llvm, .linker = .new, .pic = .pic }, + .{ .cpu = .{ .x86_64 = .{} }, .os = .{ .rtems = .{} }, .abi = .{ .none = .{} }, .cache_mode = .whole, .backend = .llvm, .linker = .new, .pic = .pic }, + .{ .cpu = .{ .x86_64 = .{} }, .os = .{ .serenity = .{} }, .abi = .{ .none = .{} }, .cache_mode = .whole, .backend = .llvm, .linker = .new, .pic = .pic }, .{ .cpu = .{ .x86_64 = .{} }, .os = .{ .uefi = .{} }, .abi = .{ .none = .{} }, .cache_mode = .whole, .backend = .llvm, .linker = .lld, .pic = .pic }, .{ .cpu = .{ .x86_64 = .{} }, .os = .{ .windows = .{} }, .abi = .{ .gnu = .{} }, .cache_mode = .whole, .backend = .llvm, .linker = .lld, .pic = .pic }, .{ .cpu = .{ .x86_64 = .{} }, .os = .{ .windows = .{} }, .abi = .{ .itanium = .{} }, .cache_mode = .whole, .backend = .llvm, .linker = .lld, .pic = .pic }, diff --git a/test/llvm/nonnull b/test/llvm/nonnull new file mode 100644 index 0000000000000000000000000000000000000000..90d904ba6df7befeace21f9bf6b27e4cc4fec35c --- /dev/null +++ b/test/llvm/nonnull @@ -0,0 +1,44 @@ +#skip amdgcn-amdhsa-none-baseline-whole-llvm-lld-pic +#skip amdgcn-amdpal-none-baseline-whole-llvm-lld-pic +#skip amdgcn-mesa3d-none-baseline-whole-llvm-lld-pic + +#skip nvptx-cuda-none-baseline-whole-llvm-lld-pic +#skip nvptx-nvcl-none-baseline-whole-llvm-lld-pic + +#skip nvptx64-cuda-none-baseline-whole-llvm-lld-pic +#skip nvptx64-nvcl-none-baseline-whole-llvm-lld-pic + +#skip x86_64-linux-gnux32-baseline-whole-llvm-new-pic +#skip x86_64-linux-muslx32-baseline-whole-llvm-new-pic +#skip x86_64-linux-x32-baseline-whole-llvm-new-pic + +#obj { +--name test -fno-lld -fno-new-linker -ofmt=llvmir +-Mroot=test.zig +#} + +#write test.zig { +export fn entry(ptr: *i16) i16 { + return ptr.*; +} +#} +#update "store" +#check llvm { +define #...@test.entry(ptr #...nonnull #...%0) #...{ +#...load i16, ptr %0#... +} + +#} + +#write test.zig { +export fn entry(ptr: *i16) void { + ptr.* = 42; +} +#} +#update "load" +#check llvm { +define #...@test.entry(ptr #...nonnull #...%0) #...{ +#...store i16 42, ptr %0#... +} + +#} diff --git a/test/llvm-ir/unused_load b/test/llvm/unused_load similarity index 51% rename from test/llvm-ir/unused_load rename to test/llvm/unused_load index 8f6f3a59cfa74bf420520802d2559b6f49bbe948..b18d0e52d080e7c6769c3f562db251c4df2378bc 100644 --- a/test/llvm-ir/unused_load +++ b/test/llvm/unused_load @@ -1,5 +1,35 @@ +#skip amdgcn-amdhsa-none-baseline-whole-llvm-lld-pic +#skip amdgcn-amdpal-none-baseline-whole-llvm-lld-pic +#skip amdgcn-mesa3d-none-baseline-whole-llvm-lld-pic + +#skip nvptx-cuda-none-baseline-whole-llvm-lld-pic +#skip nvptx-nvcl-none-baseline-whole-llvm-lld-pic + +#skip nvptx64-cuda-none-baseline-whole-llvm-lld-pic +#skip nvptx64-nvcl-none-baseline-whole-llvm-lld-pic + +#skip spirv32-opencl-none-baseline-whole-llvm-lld-pic +#skip spirv32-opengl-none-baseline-whole-llvm-lld-pic +#skip spirv32-vulkan-none-baseline-whole-llvm-lld-pic + +#skip spirv64-amdhsa-none-baseline-whole-llvm-lld-pic +#skip spirv64-opencl-none-baseline-whole-llvm-lld-pic +#skip spirv64-vulkan-none-baseline-whole-llvm-lld-pic + +#skip wasm32-emscripten-none-baseline-whole-llvm-lld-pic +#skip wasm32-freestanding-none-baseline-whole-llvm-lld-pic +#skip wasm32-wasi-none-baseline-whole-llvm-lld-pic + +#skip wasm64-emscripten-none-baseline-whole-llvm-lld-pic +#skip wasm64-freestanding-none-baseline-whole-llvm-lld-pic +#skip wasm64-wasi-none-baseline-whole-llvm-lld-pic + +#skip x86_64-linux-gnux32-baseline-whole-llvm-new-pic +#skip x86_64-linux-muslx32-baseline-whole-llvm-new-pic +#skip x86_64-linux-x32-baseline-whole-llvm-new-pic + #obj { ---name test +--name test -fno-lld -fno-new-linker -ofmt=llvmir -Mroot=test.zig #} -- 2.54.0