From 88dd682155a38843517ca79ae84f1f0a0d3c5cf9 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Sat, 3 Jan 2026 00:52:37 -0800 Subject: [PATCH] Compilation: revert bad code transformation I added `unreachable` in this branch based on a misunderstanding of the original control flow. --- src/Compilation.zig | 61 ++++++++++++++++++++++----------------------- 1 file changed, 30 insertions(+), 31 deletions(-) diff --git a/src/Compilation.zig b/src/Compilation.zig index 4b5b1e3ff8..82f45ee9f0 100644 --- a/src/Compilation.zig +++ b/src/Compilation.zig @@ -6374,41 +6374,40 @@ fn updateCObject(comp: *Compilation, c_object: *CObject, c_obj_prog_node: std.Pr }, else => std.process.abort(), } - unreachable; - } + } else { + var child = try std.process.spawn(io, .{ + .argv = argv.items, + .stdin = .ignore, + .stdout = .ignore, + .stderr = .pipe, + }); - var child = try std.process.spawn(io, .{ - .argv = argv.items, - .stdin = .ignore, - .stdout = .ignore, - .stderr = .pipe, - }); + var stderr_reader = child.stderr.?.readerStreaming(io, &.{}); + const stderr = try stderr_reader.interface.allocRemaining(arena, .limited(std.math.maxInt(u32))); - var stderr_reader = child.stderr.?.readerStreaming(io, &.{}); - const stderr = try stderr_reader.interface.allocRemaining(arena, .limited(std.math.maxInt(u32))); + const term = child.wait(io) catch |err| + return comp.failCObj(c_object, "failed to spawn zig clang {s}: {t}", .{ argv.items[0], err }); - const term = child.wait(io) catch |err| - return comp.failCObj(c_object, "failed to spawn zig clang {s}: {t}", .{ argv.items[0], err }); - - switch (term) { - .exited => |code| if (code != 0) if (out_diag_path) |diag_file_path| { - const bundle = CObject.Diag.Bundle.parse(gpa, io, diag_file_path) catch |err| { - log.err("{}: failed to parse clang diagnostics: {s}", .{ err, stderr }); + switch (term) { + .exited => |code| if (code != 0) if (out_diag_path) |diag_file_path| { + const bundle = CObject.Diag.Bundle.parse(gpa, io, diag_file_path) catch |err| { + log.err("{}: failed to parse clang diagnostics: {s}", .{ err, stderr }); + return comp.failCObj(c_object, "clang exited with code {d}", .{code}); + }; + return comp.failCObjWithOwnedDiagBundle(c_object, bundle); + } else { + log.err("clang failed with stderr: {s}", .{stderr}); return comp.failCObj(c_object, "clang exited with code {d}", .{code}); - }; - return comp.failCObjWithOwnedDiagBundle(c_object, bundle); - } else { - log.err("clang failed with stderr: {s}", .{stderr}); - return comp.failCObj(c_object, "clang exited with code {d}", .{code}); - }, - .signal => |sig| { - log.err("clang failed with stderr: {s}", .{stderr}); - return comp.failCObj(c_object, "clang terminated with signal {t}", .{sig}); - }, - else => { - log.err("clang terminated with stderr: {s}", .{stderr}); - return comp.failCObj(c_object, "clang terminated unexpectedly", .{}); - }, + }, + .signal => |sig| { + log.err("clang failed with stderr: {s}", .{stderr}); + return comp.failCObj(c_object, "clang terminated with signal {t}", .{sig}); + }, + else => { + log.err("clang terminated with stderr: {s}", .{stderr}); + return comp.failCObj(c_object, "clang terminated unexpectedly", .{}); + }, + } } } else { const exit_code = try clangMain(arena, argv.items);