From 93ae386f560e7a3464df31b7c9bc9acdc231bc3f Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Sun, 24 Jul 2022 14:31:00 -0700 Subject: [PATCH] stage2: don't skip liveness or codegen if -femit-asm is supplied Fixes Godbolt's CLI usage of Zig. --- ci/zinc/linux_test.sh | 2 +- src/Module.zig | 14 +++++++++++--- test/cli.zig | 25 +++++++++++++++++-------- 3 files changed, 29 insertions(+), 12 deletions(-) diff --git a/ci/zinc/linux_test.sh b/ci/zinc/linux_test.sh index c6e59302d0..2a2143a285 100755 --- a/ci/zinc/linux_test.sh +++ b/ci/zinc/linux_test.sh @@ -61,9 +61,9 @@ stage3/bin/zig build test-asm-link -fqemu -fwasmtime -Denable-llvm stage3/bin/zig build test-fmt -fqemu -fwasmtime -Denable-llvm stage3/bin/zig build test-translate-c -fqemu -fwasmtime -Denable-llvm stage3/bin/zig build test-standalone -fqemu -fwasmtime -Denable-llvm +stage3/bin/zig build test-cli -fqemu -fwasmtime -Denable-llvm $STAGE1_ZIG build test-stack-traces -fqemu -fwasmtime -$STAGE1_ZIG build test-cli -fqemu -fwasmtime $STAGE1_ZIG build test-run-translated-c -fqemu -fwasmtime $STAGE1_ZIG build docs -fqemu -fwasmtime $STAGE1_ZIG build test-cases -fqemu -fwasmtime diff --git a/src/Module.zig b/src/Module.zig index fd97e5c948..c144c9acbd 100644 --- a/src/Module.zig +++ b/src/Module.zig @@ -4122,13 +4122,21 @@ pub fn ensureFuncBodyAnalyzed(mod: *Module, func: *Fn) SemaError!void { }; defer air.deinit(gpa); - if (mod.comp.bin_file.options.emit == null) return; + const comp = mod.comp; + + if (comp.bin_file.options.emit == null and + comp.emit_asm == null and + comp.emit_llvm_ir == null and + comp.emit_llvm_bc == null) + { + return; + } log.debug("analyze liveness of {s}", .{decl.name}); var liveness = try Liveness.analyze(gpa, air); defer liveness.deinit(gpa); - if (builtin.mode == .Debug and mod.comp.verbose_air) { + if (builtin.mode == .Debug and comp.verbose_air) { const fqn = try decl.getFullyQualifiedName(mod); defer mod.gpa.free(fqn); @@ -4137,7 +4145,7 @@ pub fn ensureFuncBodyAnalyzed(mod: *Module, func: *Fn) SemaError!void { std.debug.print("# End Function AIR: {s}\n\n", .{fqn}); } - mod.comp.bin_file.updateFunc(mod, func, air, liveness) catch |err| switch (err) { + comp.bin_file.updateFunc(mod, func, air, liveness) catch |err| switch (err) { error.OutOfMemory => return error.OutOfMemory, error.AnalysisFail => { decl.analysis = .codegen_failure; diff --git a/test/cli.zig b/test/cli.zig index 3ba74f1ec1..7c0238e771 100644 --- a/test/cli.zig +++ b/test/cli.zig @@ -33,17 +33,26 @@ pub fn main() !void { defer fs.cwd().deleteTree(dir_path) catch {}; const TestFn = fn ([]const u8, []const u8) anyerror!void; - const test_fns = [_]TestFn{ - testZigInitLib, - testZigInitExe, - testGodboltApi, - testMissingOutputPath, - testZigFmt, + const Test = struct { + func: TestFn, + name: []const u8, }; - inline for (test_fns) |testFn| { + const tests = [_]Test{ + .{ .func = testZigInitLib, .name = "zig init-lib" }, + .{ .func = testZigInitExe, .name = "zig init-exe" }, + .{ .func = testGodboltApi, .name = "godbolt API" }, + .{ .func = testMissingOutputPath, .name = "missing output path" }, + .{ .func = testZigFmt, .name = "zig fmt" }, + }; + inline for (tests) |t| { try fs.cwd().deleteTree(dir_path); try fs.cwd().makeDir(dir_path); - try testFn(zig_exe, dir_path); + t.func(zig_exe, dir_path) catch |err| { + std.debug.print("test '{s}' failed: {s}\n", .{ + t.name, @errorName(err), + }); + return err; + }; } }