| author | |
| committer | |
| log | 17255bed41a4b2c31a3f4342d51aa80a6f9d6b0b |
| tree | fc98a4630e04378699dbf7c51513e59f385524f0 |
| parent | 996eb01746498e0ec5e162ed40d1f3c913891150 |
| parent | e7ea7d3480bd015053d34474a23cdf407a6a545f |
| signature |
cbe: fix bug where empty enum would be generated2 files changed, 47 insertions(+), 16 deletions(-)
src/codegen/c.zig+16-14| ... | ... | @@ -2406,22 +2406,24 @@ pub fn genErrDecls(o: *Object) !void { |
| 2406 | 2406 | const mod = o.dg.module; |
| 2407 | 2407 | const writer = o.writer(); |
| 2408 | 2408 | |
| 2409 | try writer.writeAll("enum {\n"); | |
| 2410 | o.indent_writer.pushIndent(); | |
| 2411 | 2409 | var max_name_len: usize = 0; |
| 2412 | for (mod.global_error_set.keys()[1..], 1..) |name_nts, value| { | |
| 2413 | const name = mod.intern_pool.stringToSlice(name_nts); | |
| 2414 | max_name_len = @max(name.len, max_name_len); | |
| 2415 | const err_val = try mod.intern(.{ .err = .{ | |
| 2416 | .ty = .anyerror_type, | |
| 2417 | .name = name_nts, | |
| 2418 | } }); | |
| 2419 | try o.dg.renderValue(writer, Type.anyerror, err_val.toValue(), .Other); | |
| 2420 | try writer.print(" = {d}u,\n", .{value}); | |
| 2410 | // do not generate an invalid empty enum when the global error set is empty | |
| 2411 | if (mod.global_error_set.keys().len > 1) { | |
| 2412 | try writer.writeAll("enum {\n"); | |
| 2413 | o.indent_writer.pushIndent(); | |
| 2414 | for (mod.global_error_set.keys()[1..], 1..) |name_nts, value| { | |
| 2415 | const name = mod.intern_pool.stringToSlice(name_nts); | |
| 2416 | max_name_len = @max(name.len, max_name_len); | |
| 2417 | const err_val = try mod.intern(.{ .err = .{ | |
| 2418 | .ty = .anyerror_type, | |
| 2419 | .name = name_nts, | |
| 2420 | } }); | |
| 2421 | try o.dg.renderValue(writer, Type.anyerror, err_val.toValue(), .Other); | |
| 2422 | try writer.print(" = {d}u,\n", .{value}); | |
| 2423 | } | |
| 2424 | o.indent_writer.popIndent(); | |
| 2425 | try writer.writeAll("};\n"); | |
| 2421 | 2426 | } |
| 2422 | o.indent_writer.popIndent(); | |
| 2423 | try writer.writeAll("};\n"); | |
| 2424 | ||
| 2425 | 2427 | const array_identifier = "zig_errorName"; |
| 2426 | 2428 | const name_prefix = array_identifier ++ "_"; |
| 2427 | 2429 | const name_buf = try o.dg.gpa.alloc(u8, name_prefix.len + max_name_len); |
test/src/Cases.zig+31-2| ... | ... | @@ -467,6 +467,9 @@ pub fn lowerToBuildSteps( |
| 467 | 467 | cases_dir_path: []const u8, |
| 468 | 468 | incremental_exe: *std.Build.Step.Compile, |
| 469 | 469 | ) void { |
| 470 | const host = std.zig.system.NativeTargetInfo.detect(.{}) catch |err| | |
| 471 | std.debug.panic("unable to detect notive host: {s}\n", .{@errorName(err)}); | |
| 472 | ||
| 470 | 473 | for (self.incremental_cases.items) |incr_case| { |
| 471 | 474 | if (true) { |
| 472 | 475 | // TODO: incremental tests are disabled for now, as incremental compilation bugs were |
| ... | ... | @@ -569,8 +572,34 @@ pub fn lowerToBuildSteps( |
| 569 | 572 | artifact.expect_errors = expected_msgs; |
| 570 | 573 | parent_step.dependOn(&artifact.step); |
| 571 | 574 | }, |
| 572 | .Execution => |expected_stdout| { | |
| 573 | const run = b.addRunArtifact(artifact); | |
| 575 | .Execution => |expected_stdout| no_exec: { | |
| 576 | const run = if (case.target.ofmt == .c) run_step: { | |
| 577 | const target_info = std.zig.system.NativeTargetInfo.detect(case.target) catch |err| | |
| 578 | std.debug.panic("unable to detect notive host: {s}\n", .{@errorName(err)}); | |
| 579 | if (host.getExternalExecutor(target_info, .{ .link_libc = true }) != .native) { | |
| 580 | // We wouldn't be able to run the compiled C code. | |
| 581 | break :no_exec; | |
| 582 | } | |
| 583 | const run_c = b.addSystemCommand(&.{ | |
| 584 | b.zig_exe, | |
| 585 | "run", | |
| 586 | "-cflags", | |
| 587 | "-Ilib", | |
| 588 | "-std=c99", | |
| 589 | "-pedantic", | |
| 590 | "-Werror", | |
| 591 | "-Wno-dollar-in-identifier-extension", | |
| 592 | "-Wno-incompatible-library-redeclaration", // https://github.com/ziglang/zig/issues/875 | |
| 593 | "-Wno-incompatible-pointer-types", | |
| 594 | "-Wno-overlength-strings", | |
| 595 | "--", | |
| 596 | "-lc", | |
| 597 | "-target", | |
| 598 | case.target.zigTriple(b.allocator) catch @panic("OOM"), | |
| 599 | }); | |
| 600 | run_c.addArtifactArg(artifact); | |
| 601 | break :run_step run_c; | |
| 602 | } else b.addRunArtifact(artifact); | |
| 574 | 603 | run.skip_foreign_checks = true; |
| 575 | 604 | if (!case.is_test) { |
| 576 | 605 | run.expectStdOutEqual(expected_stdout); |