authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2022-10-15 02:34:34-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-10-15 14:18:35-04:00
logc7f98332383d71a57699426027e82c435e91addc
treeb6a97bb72808d47a001085403254c0fc9d75b82b
parentcb0e22db4e18dd803e1edd681c836fadbae0ea6f

Module: fix early exit conditions during compilation

* `--verbose-llvm-ir` should trigger analysis and codegen * `-femit-asm` etc should trigger codegen even with `-fno-emit-bin` Closes #12588

4 files changed, 36 insertions(+), 7 deletions(-)

src/Module.zig+11-7
......@@ -4319,10 +4319,9 @@ pub fn ensureFuncBodyAnalyzed(mod: *Module, func: *Fn) SemaError!void {
43194319 comp.emit_llvm_bc == null);
43204320
43214321 const dump_air = builtin.mode == .Debug and comp.verbose_air;
4322 const dump_llvm_ir = builtin.mode == .Debug and comp.verbose_llvm_ir;
43224323
4323 if (no_bin_file and !dump_air) {
4324 return;
4325 }
4324 if (no_bin_file and !dump_air and !dump_llvm_ir) return;
43264325
43274326 log.debug("analyze liveness of {s}", .{decl.name});
43284327 var liveness = try Liveness.analyze(gpa, air);
......@@ -4337,9 +4336,7 @@ pub fn ensureFuncBodyAnalyzed(mod: *Module, func: *Fn) SemaError!void {
43374336 std.debug.print("# End Function AIR: {s}\n\n", .{fqn});
43384337 }
43394338
4340 if (no_bin_file) {
4341 return;
4342 }
4339 if (no_bin_file and !dump_llvm_ir) return;
43434340
43444341 comp.bin_file.updateFunc(mod, func, air, liveness) catch |err| switch (err) {
43454342 error.OutOfMemory => return error.OutOfMemory,
......@@ -6484,7 +6481,14 @@ pub fn populateTestFunctions(mod: *Module) !void {
64846481pub fn linkerUpdateDecl(mod: *Module, decl_index: Decl.Index) !void {
64856482 const comp = mod.comp;
64866483
6487 if (comp.bin_file.options.emit == null) return;
6484 const no_bin_file = (comp.bin_file.options.emit == null and
6485 comp.emit_asm == null and
6486 comp.emit_llvm_ir == null and
6487 comp.emit_llvm_bc == null);
6488
6489 const dump_llvm_ir = builtin.mode == .Debug and comp.verbose_llvm_ir;
6490
6491 if (no_bin_file and !dump_llvm_ir) return;
64886492
64896493 const decl = mod.declPtr(decl_index);
64906494
test/standalone.zig+1
......@@ -103,4 +103,5 @@ pub fn addCases(cases: *tests.StandaloneContext) void {
103103
104104 cases.addBuildFile("test/standalone/issue_13030/build.zig", .{ .build_modes = true });
105105 cases.addBuildFile("test/standalone/emit_asm_and_bin/build.zig", .{});
106 cases.addBuildFile("test/standalone/issue_12588/build.zig", .{});
106107}
test/standalone/issue_12588/build.zig created+18
......@@ -0,0 +1,18 @@
1const std = @import("std");
2const Builder = std.build.Builder;
3
4pub fn build(b: *Builder) void {
5 const mode = b.standardReleaseOptions();
6 const target = b.standardTargetOptions(.{});
7
8 const obj = b.addObject("main", "main.zig");
9 obj.setBuildMode(mode);
10 obj.setTarget(target);
11 obj.emit_llvm_ir = .{ .emit_to = b.pathFromRoot("main.ll") };
12 obj.emit_llvm_bc = .{ .emit_to = b.pathFromRoot("main.bc") };
13 obj.emit_bin = .no_emit;
14 b.default_step.dependOn(&obj.step);
15
16 const test_step = b.step("test", "Test the program");
17 test_step.dependOn(&obj.step);
18}
test/standalone/issue_12588/main.zig created+6
......@@ -0,0 +1,6 @@
1const std = @import("std");
2
3export fn strFromFloatHelp(float: f64) void {
4 var buf: [400]u8 = undefined;
5 _ = std.fmt.bufPrint(&buf, "{d}", .{float}) catch unreachable;
6}