authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-07-24 14:31:00-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-07-24 15:02:05-07:00
log93ae386f560e7a3464df31b7c9bc9acdc231bc3f
tree4d279258d3812a47b5f5188c9304937c6133fa98
parentbe294e3744b221e7a7aad3ce8fbd1a30148487bc

stage2: don't skip liveness or codegen if -femit-asm is supplied

Fixes Godbolt's CLI usage of Zig.

3 files changed, 29 insertions(+), 12 deletions(-)

ci/zinc/linux_test.sh+1-1
...@@ -61,9 +61,9 @@ stage3/bin/zig build test-asm-link -fqemu -fwasmtime -Denable-llvm...@@ -61,9 +61,9 @@ stage3/bin/zig build test-asm-link -fqemu -fwasmtime -Denable-llvm
61stage3/bin/zig build test-fmt -fqemu -fwasmtime -Denable-llvm61stage3/bin/zig build test-fmt -fqemu -fwasmtime -Denable-llvm
62stage3/bin/zig build test-translate-c -fqemu -fwasmtime -Denable-llvm62stage3/bin/zig build test-translate-c -fqemu -fwasmtime -Denable-llvm
63stage3/bin/zig build test-standalone -fqemu -fwasmtime -Denable-llvm63stage3/bin/zig build test-standalone -fqemu -fwasmtime -Denable-llvm
64stage3/bin/zig build test-cli -fqemu -fwasmtime -Denable-llvm
6465
65$STAGE1_ZIG build test-stack-traces -fqemu -fwasmtime66$STAGE1_ZIG build test-stack-traces -fqemu -fwasmtime
66$STAGE1_ZIG build test-cli -fqemu -fwasmtime
67$STAGE1_ZIG build test-run-translated-c -fqemu -fwasmtime67$STAGE1_ZIG build test-run-translated-c -fqemu -fwasmtime
68$STAGE1_ZIG build docs -fqemu -fwasmtime68$STAGE1_ZIG build docs -fqemu -fwasmtime
69$STAGE1_ZIG build test-cases -fqemu -fwasmtime69$STAGE1_ZIG build test-cases -fqemu -fwasmtime
src/Module.zig+11-3
...@@ -4122,13 +4122,21 @@ pub fn ensureFuncBodyAnalyzed(mod: *Module, func: *Fn) SemaError!void {...@@ -4122,13 +4122,21 @@ pub fn ensureFuncBodyAnalyzed(mod: *Module, func: *Fn) SemaError!void {
4122 };4122 };
4123 defer air.deinit(gpa);4123 defer air.deinit(gpa);
41244124
4125 if (mod.comp.bin_file.options.emit == null) return;4125 const comp = mod.comp;
4126
4127 if (comp.bin_file.options.emit == null and
4128 comp.emit_asm == null and
4129 comp.emit_llvm_ir == null and
4130 comp.emit_llvm_bc == null)
4131 {
4132 return;
4133 }
41264134
4127 log.debug("analyze liveness of {s}", .{decl.name});4135 log.debug("analyze liveness of {s}", .{decl.name});
4128 var liveness = try Liveness.analyze(gpa, air);4136 var liveness = try Liveness.analyze(gpa, air);
4129 defer liveness.deinit(gpa);4137 defer liveness.deinit(gpa);
41304138
4131 if (builtin.mode == .Debug and mod.comp.verbose_air) {4139 if (builtin.mode == .Debug and comp.verbose_air) {
4132 const fqn = try decl.getFullyQualifiedName(mod);4140 const fqn = try decl.getFullyQualifiedName(mod);
4133 defer mod.gpa.free(fqn);4141 defer mod.gpa.free(fqn);
41344142
...@@ -4137,7 +4145,7 @@ pub fn ensureFuncBodyAnalyzed(mod: *Module, func: *Fn) SemaError!void {...@@ -4137,7 +4145,7 @@ pub fn ensureFuncBodyAnalyzed(mod: *Module, func: *Fn) SemaError!void {
4137 std.debug.print("# End Function AIR: {s}\n\n", .{fqn});4145 std.debug.print("# End Function AIR: {s}\n\n", .{fqn});
4138 }4146 }
41394147
4140 mod.comp.bin_file.updateFunc(mod, func, air, liveness) catch |err| switch (err) {4148 comp.bin_file.updateFunc(mod, func, air, liveness) catch |err| switch (err) {
4141 error.OutOfMemory => return error.OutOfMemory,4149 error.OutOfMemory => return error.OutOfMemory,
4142 error.AnalysisFail => {4150 error.AnalysisFail => {
4143 decl.analysis = .codegen_failure;4151 decl.analysis = .codegen_failure;
test/cli.zig+17-8
...@@ -33,17 +33,26 @@ pub fn main() !void {...@@ -33,17 +33,26 @@ pub fn main() !void {
33 defer fs.cwd().deleteTree(dir_path) catch {};33 defer fs.cwd().deleteTree(dir_path) catch {};
3434
35 const TestFn = fn ([]const u8, []const u8) anyerror!void;35 const TestFn = fn ([]const u8, []const u8) anyerror!void;
36 const test_fns = [_]TestFn{36 const Test = struct {
37 testZigInitLib,37 func: TestFn,
38 testZigInitExe,38 name: []const u8,
39 testGodboltApi,
40 testMissingOutputPath,
41 testZigFmt,
42 };39 };
43 inline for (test_fns) |testFn| {40 const tests = [_]Test{
41 .{ .func = testZigInitLib, .name = "zig init-lib" },
42 .{ .func = testZigInitExe, .name = "zig init-exe" },
43 .{ .func = testGodboltApi, .name = "godbolt API" },
44 .{ .func = testMissingOutputPath, .name = "missing output path" },
45 .{ .func = testZigFmt, .name = "zig fmt" },
46 };
47 inline for (tests) |t| {
44 try fs.cwd().deleteTree(dir_path);48 try fs.cwd().deleteTree(dir_path);
45 try fs.cwd().makeDir(dir_path);49 try fs.cwd().makeDir(dir_path);
46 try testFn(zig_exe, dir_path);50 t.func(zig_exe, dir_path) catch |err| {
51 std.debug.print("test '{s}' failed: {s}\n", .{
52 t.name, @errorName(err),
53 });
54 return err;
55 };
47 }56 }
48}57}
4958