From 5f31070b8bb204ce7d42881903805c7a4b2263d0 Mon Sep 17 00:00:00 2001 From: Jacob Young Date: Wed, 2 Nov 2022 01:23:28 -0400 Subject: [PATCH] cbe: hack around invalid Air Can be changed to `!inst_ty.hisRuntimeBitsIgnoreComptime()` when the "result location with inferred type ends up being pointer to comptime_int" test stops producing Air containing a `bitcast(*comptime_int, ...)`. See #13410 --- src/codegen/c.zig | 8 ++++---- test/behavior/if.zig | 1 - 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/codegen/c.zig b/src/codegen/c.zig index 2762123b64b589c48b201b1ff3e7d15e23bc86de..f3fdb6ae8902e75fa89163d697cb9b6fa26968de 100644 --- a/src/codegen/c.zig +++ b/src/codegen/c.zig @@ -79,7 +79,6 @@ const BuiltinInfo = enum { Bits, }; -/// TODO make this not cut off at 128 bytes fn formatTypeAsCIdentifier( data: FormatTypeAsCIdentContext, comptime fmt: []const u8, @@ -3666,14 +3665,15 @@ fn airBr(f: *Function, inst: Air.Inst.Index) !CValue { } fn airBitcast(f: *Function, inst: Air.Inst.Index) !CValue { - if (f.liveness.isUnused(inst)) - return CValue.none; + const inst_ty = f.air.typeOfIndex(inst); + // No IgnoreComptime until Sema stops giving us garbage Air. + // https://github.com/ziglang/zig/issues/13410 + if (f.liveness.isUnused(inst) or !inst_ty.hasRuntimeBits()) return CValue.none; const ty_op = f.air.instructions.items(.data)[inst].ty_op; const operand = try f.resolveInst(ty_op.operand); const writer = f.object.writer(); - const inst_ty = f.air.typeOfIndex(inst); if (inst_ty.isPtrAtRuntime() and f.air.typeOf(ty_op.operand).isPtrAtRuntime()) { diff --git a/test/behavior/if.zig b/test/behavior/if.zig index 8117c1db3fade564cb3c89096ece18c7e07ebba9..8a001a65d4b61db15a56889c903490a2cd2c19db 100644 --- a/test/behavior/if.zig +++ b/test/behavior/if.zig @@ -146,7 +146,6 @@ test "result location with inferred type ends up being pointer to comptime_int" if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; - if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; var a: ?u32 = 1234; var b: u32 = 2000; -- 2.54.0