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 {...@@ -2409,10 +2409,11 @@ fn airLoad(f: *Function, inst: Air.Inst.Index) !CValue {
2409 const ty_op = f.air.instructions.items(.data)[inst].ty_op;2409 const ty_op = f.air.instructions.items(.data)[inst].ty_op;
2410 const is_volatile = f.air.typeOf(ty_op.operand).isVolatilePtr();2410 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))
2413 return CValue.none;2415 return CValue.none;
24142416
2415 const inst_ty = f.air.typeOfIndex(inst);
2416 const is_array = inst_ty.zigTypeTag() == .Array;2417 const is_array = inst_ty.zigTypeTag() == .Array;
2417 const operand = try f.resolveInst(ty_op.operand);2418 const operand = try f.resolveInst(ty_op.operand);
2418 const writer = f.object.writer();2419 const writer = f.object.writer();
...@@ -2565,9 +2566,11 @@ fn airStoreUndefined(f: *Function, dest_ptr: CValue) !CValue {...@@ -2565,9 +2566,11 @@ fn airStoreUndefined(f: *Function, dest_ptr: CValue) !CValue {
2565fn airStore(f: *Function, inst: Air.Inst.Index) !CValue {2566fn airStore(f: *Function, inst: Air.Inst.Index) !CValue {
2566 // *a = b;2567 // *a = b;
2567 const bin_op = f.air.instructions.items(.data)[inst].bin_op;2568 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
2568 const dest_ptr = try f.resolveInst(bin_op.lhs);2572 const dest_ptr = try f.resolveInst(bin_op.lhs);
2569 const src_val = try f.resolveInst(bin_op.rhs);2573 const src_val = try f.resolveInst(bin_op.rhs);
2570 const lhs_child_type = f.air.typeOf(bin_op.lhs).childType();
25712574
2572 // TODO Sema should emit a different instruction when the store should2575 // TODO Sema should emit a different instruction when the store should
2573 // possibly do the safety 0xaa bytes for undefined.2576 // possibly do the safety 0xaa bytes for undefined.
test/behavior/empty_union.zig-2
...@@ -3,7 +3,6 @@ const std = @import("std");...@@ -3,7 +3,6 @@ const std = @import("std");
3const expect = std.testing.expect;3const expect = std.testing.expect;
44
5test "switch on empty enum" {5test "switch on empty enum" {
6 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
7 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO6 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
87
9 const E = enum {};8 const E = enum {};
...@@ -29,7 +28,6 @@ test "switch on empty auto numbered tagged union" {...@@ -29,7 +28,6 @@ test "switch on empty auto numbered tagged union" {
29}28}
3029
31test "switch on empty tagged union" {30test "switch on empty tagged union" {
32 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
33 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO31 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
34 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO32 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
3533