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
6161stage3/bin/zig build test-fmt -fqemu -fwasmtime -Denable-llvm
6262stage3/bin/zig build test-translate-c -fqemu -fwasmtime -Denable-llvm
6363stage3/bin/zig build test-standalone -fqemu -fwasmtime -Denable-llvm
64stage3/bin/zig build test-cli -fqemu -fwasmtime -Denable-llvm
6465
6566$STAGE1_ZIG build test-stack-traces -fqemu -fwasmtime
66$STAGE1_ZIG build test-cli -fqemu -fwasmtime
6767$STAGE1_ZIG build test-run-translated-c -fqemu -fwasmtime
6868$STAGE1_ZIG build docs -fqemu -fwasmtime
6969$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 {
41224122 };
41234123 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
41274135 log.debug("analyze liveness of {s}", .{decl.name});
41284136 var liveness = try Liveness.analyze(gpa, air);
41294137 defer liveness.deinit(gpa);
41304138
4131 if (builtin.mode == .Debug and mod.comp.verbose_air) {
4139 if (builtin.mode == .Debug and comp.verbose_air) {
41324140 const fqn = try decl.getFullyQualifiedName(mod);
41334141 defer mod.gpa.free(fqn);
41344142
......@@ -4137,7 +4145,7 @@ pub fn ensureFuncBodyAnalyzed(mod: *Module, func: *Fn) SemaError!void {
41374145 std.debug.print("# End Function AIR: {s}\n\n", .{fqn});
41384146 }
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) {
41414149 error.OutOfMemory => return error.OutOfMemory,
41424150 error.AnalysisFail => {
41434151 decl.analysis = .codegen_failure;
test/cli.zig+17-8
......@@ -33,17 +33,26 @@ pub fn main() !void {
3333 defer fs.cwd().deleteTree(dir_path) catch {};
3434
3535 const TestFn = fn ([]const u8, []const u8) anyerror!void;
36 const test_fns = [_]TestFn{
37 testZigInitLib,
38 testZigInitExe,
39 testGodboltApi,
40 testMissingOutputPath,
41 testZigFmt,
36 const Test = struct {
37 func: TestFn,
38 name: []const u8,
4239 };
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| {
4448 try fs.cwd().deleteTree(dir_path);
4549 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 };
4756 }
4857}
4958