Commit 5f31070b8b

Jacob Young <jacobly0@users.noreply.github.com>
2022-11-02 06:23:28
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
1 parent d8635af
Changed files (2)
src
codegen
test
behavior
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())
     {
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;