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

Fixes Godbolt's CLI usage of Zig.
This commit is contained in:
Andrew Kelley 2022-07-24 14:31:00 -07:00
parent be294e3744
commit 93ae386f56
3 changed files with 29 additions and 12 deletions

View file

@ -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

View file

@ -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;

View file

@ -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;
};
}
}