diff --git a/src/codegen/c.zig b/src/codegen/c.zig index 8052c8116b..897af5ef65 100644 --- a/src/codegen/c.zig +++ b/src/codegen/c.zig @@ -2078,7 +2078,6 @@ pub fn genGlobalAsm(mod: *Module, code: *std.ArrayList(u8)) !void { } pub fn genErrDecls(o: *Object) !void { - if (o.dg.module.global_error_set.size == 0) return; const writer = o.writer(); try writer.writeAll("enum {\n"); @@ -2373,7 +2372,7 @@ fn genBody(f: *Function, body: []const Air.Inst.Index) error{ AnalysisFail, OutO .cmp_neq => try airEquality(f, inst, "!((", "!="), .cmp_vector => return f.fail("TODO: C backend: implement cmp_vector", .{}), - .cmp_lt_errors_len => return f.fail("TODO: C backend: implement cmp_lt_errors_len", .{}), + .cmp_lt_errors_len => try airCmpLtErrorsLen(f, inst), // bool_and and bool_or are non-short-circuit operations .bool_and, .bit_and => try airBinOp(f, inst, "&", "and", .None), @@ -3176,6 +3175,21 @@ fn airEquality( return local; } +fn airCmpLtErrorsLen(f: *Function, inst: Air.Inst.Index) !CValue { + if (f.liveness.isUnused(inst)) return CValue.none; + + const un_op = f.air.instructions.items(.data)[inst].un_op; + const inst_ty = f.air.typeOfIndex(inst); + const operand = try f.resolveInst(un_op); + + const writer = f.object.writer(); + const local = try f.allocLocal(inst_ty, .Const); + try writer.writeAll(" = "); + try f.writeCValue(writer, operand, .Other); + try writer.print(" < sizeof({ }) / sizeof(*{0 });\n", .{fmtIdent("zig_errorName")}); + return local; +} + fn airPtrAddSub(f: *Function, inst: Air.Inst.Index, operator: u8) !CValue { if (f.liveness.isUnused(inst)) return CValue.none; diff --git a/test/behavior/cast.zig b/test/behavior/cast.zig index 0b8787e8b6..8a0001297c 100644 --- a/test/behavior/cast.zig +++ b/test/behavior/cast.zig @@ -394,7 +394,6 @@ test "expected [*c]const u8, found [*:0]const u8" { test "explicit cast from integer to error type" { if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO - if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO