authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2022-10-08 12:37:05-04:00
committergravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2022-10-25 05:11:28-04:00
log40b5bb71618825dbdba512b43ebf8c4cb5caf153
tree91f2797baf58e4b5c6b1958e55b905b6a5993132
parent962f33ee11676934eeece4595cdc372662986f6d

cbe: fix loads and stores of 0-bit types


2 files changed, 6 insertions(+), 5 deletions(-)

src/codegen/c.zig+6-3
......@@ -2409,10 +2409,11 @@ fn airLoad(f: *Function, inst: Air.Inst.Index) !CValue {
24092409 const ty_op = f.air.instructions.items(.data)[inst].ty_op;
24102410 const is_volatile = f.air.typeOf(ty_op.operand).isVolatilePtr();
24112411
2412 if (!is_volatile and f.liveness.isUnused(inst))
2412 const inst_ty = f.air.typeOfIndex(inst);
2413 if (!inst_ty.hasRuntimeBitsIgnoreComptime() or
2414 !is_volatile and f.liveness.isUnused(inst))
24132415 return CValue.none;
24142416
2415 const inst_ty = f.air.typeOfIndex(inst);
24162417 const is_array = inst_ty.zigTypeTag() == .Array;
24172418 const operand = try f.resolveInst(ty_op.operand);
24182419 const writer = f.object.writer();
......@@ -2565,9 +2566,11 @@ fn airStoreUndefined(f: *Function, dest_ptr: CValue) !CValue {
25652566fn airStore(f: *Function, inst: Air.Inst.Index) !CValue {
25662567 // *a = b;
25672568 const bin_op = f.air.instructions.items(.data)[inst].bin_op;
2569 const lhs_child_type = f.air.typeOf(bin_op.lhs).childType();
2570 if (!lhs_child_type.hasRuntimeBitsIgnoreComptime()) return CValue.none;
2571
25682572 const dest_ptr = try f.resolveInst(bin_op.lhs);
25692573 const src_val = try f.resolveInst(bin_op.rhs);
2570 const lhs_child_type = f.air.typeOf(bin_op.lhs).childType();
25712574
25722575 // TODO Sema should emit a different instruction when the store should
25732576 // possibly do the safety 0xaa bytes for undefined.
test/behavior/empty_union.zig-2
......@@ -3,7 +3,6 @@ const std = @import("std");
33const expect = std.testing.expect;
44
55test "switch on empty enum" {
6 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
76 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
87
98 const E = enum {};
......@@ -29,7 +28,6 @@ test "switch on empty auto numbered tagged union" {
2928}
3029
3130test "switch on empty tagged union" {
32 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
3331 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
3432 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
3533