Merge pull request #16443 from notcancername/cbe-empty-enum

cbe: fix bug where empty enum would be generated
This commit is contained in:
Jacob Young 2023-07-20 02:47:26 -04:00 committed by GitHub
commit 17255bed41
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 47 additions and 16 deletions

View File

@ -2406,22 +2406,24 @@ pub fn genErrDecls(o: *Object) !void {
const mod = o.dg.module;
const writer = o.writer();
try writer.writeAll("enum {\n");
o.indent_writer.pushIndent();
var max_name_len: usize = 0;
for (mod.global_error_set.keys()[1..], 1..) |name_nts, value| {
const name = mod.intern_pool.stringToSlice(name_nts);
max_name_len = @max(name.len, max_name_len);
const err_val = try mod.intern(.{ .err = .{
.ty = .anyerror_type,
.name = name_nts,
} });
try o.dg.renderValue(writer, Type.anyerror, err_val.toValue(), .Other);
try writer.print(" = {d}u,\n", .{value});
// do not generate an invalid empty enum when the global error set is empty
if (mod.global_error_set.keys().len > 1) {
try writer.writeAll("enum {\n");
o.indent_writer.pushIndent();
for (mod.global_error_set.keys()[1..], 1..) |name_nts, value| {
const name = mod.intern_pool.stringToSlice(name_nts);
max_name_len = @max(name.len, max_name_len);
const err_val = try mod.intern(.{ .err = .{
.ty = .anyerror_type,
.name = name_nts,
} });
try o.dg.renderValue(writer, Type.anyerror, err_val.toValue(), .Other);
try writer.print(" = {d}u,\n", .{value});
}
o.indent_writer.popIndent();
try writer.writeAll("};\n");
}
o.indent_writer.popIndent();
try writer.writeAll("};\n");
const array_identifier = "zig_errorName";
const name_prefix = array_identifier ++ "_";
const name_buf = try o.dg.gpa.alloc(u8, name_prefix.len + max_name_len);

View File

@ -467,6 +467,9 @@ pub fn lowerToBuildSteps(
cases_dir_path: []const u8,
incremental_exe: *std.Build.Step.Compile,
) void {
const host = std.zig.system.NativeTargetInfo.detect(.{}) catch |err|
std.debug.panic("unable to detect notive host: {s}\n", .{@errorName(err)});
for (self.incremental_cases.items) |incr_case| {
if (true) {
// TODO: incremental tests are disabled for now, as incremental compilation bugs were
@ -569,8 +572,34 @@ pub fn lowerToBuildSteps(
artifact.expect_errors = expected_msgs;
parent_step.dependOn(&artifact.step);
},
.Execution => |expected_stdout| {
const run = b.addRunArtifact(artifact);
.Execution => |expected_stdout| no_exec: {
const run = if (case.target.ofmt == .c) run_step: {
const target_info = std.zig.system.NativeTargetInfo.detect(case.target) catch |err|
std.debug.panic("unable to detect notive host: {s}\n", .{@errorName(err)});
if (host.getExternalExecutor(target_info, .{ .link_libc = true }) != .native) {
// We wouldn't be able to run the compiled C code.
break :no_exec;
}
const run_c = b.addSystemCommand(&.{
b.zig_exe,
"run",
"-cflags",
"-Ilib",
"-std=c99",
"-pedantic",
"-Werror",
"-Wno-dollar-in-identifier-extension",
"-Wno-incompatible-library-redeclaration", // https://github.com/ziglang/zig/issues/875
"-Wno-incompatible-pointer-types",
"-Wno-overlength-strings",
"--",
"-lc",
"-target",
case.target.zigTriple(b.allocator) catch @panic("OOM"),
});
run_c.addArtifactArg(artifact);
break :run_step run_c;
} else b.addRunArtifact(artifact);
run.skip_foreign_checks = true;
if (!case.is_test) {
run.expectStdOutEqual(expected_stdout);