aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacob Young <jacobly0@users.noreply.github.com>2022-10-08 12:37:05 -0400
committerJacob Young <jacobly0@users.noreply.github.com>2022-10-25 05:11:28 -0400
commit40b5bb71618825dbdba512b43ebf8c4cb5caf153 (patch)
tree91f2797baf58e4b5c6b1958e55b905b6a5993132
parent962f33ee11676934eeece4595cdc372662986f6d (diff)
downloadzig-40b5bb71618825dbdba512b43ebf8c4cb5caf153.tar.gz
zig-40b5bb71618825dbdba512b43ebf8c4cb5caf153.zip
cbe: fix loads and stores of 0-bit types
-rw-r--r--src/codegen/c.zig9
-rw-r--r--test/behavior/empty_union.zig2
2 files changed, 6 insertions, 5 deletions
diff --git a/src/codegen/c.zig b/src/codegen/c.zig
index 39ed7cf477..f00bd28773 100644
--- a/src/codegen/c.zig
+++ b/src/codegen/c.zig
@@ -2409,10 +2409,11 @@ fn airLoad(f: *Function, inst: Air.Inst.Index) !CValue {
const ty_op = f.air.instructions.items(.data)[inst].ty_op;
const is_volatile = f.air.typeOf(ty_op.operand).isVolatilePtr();
- if (!is_volatile and f.liveness.isUnused(inst))
+ const inst_ty = f.air.typeOfIndex(inst);
+ if (!inst_ty.hasRuntimeBitsIgnoreComptime() or
+ !is_volatile and f.liveness.isUnused(inst))
return CValue.none;
- const inst_ty = f.air.typeOfIndex(inst);
const is_array = inst_ty.zigTypeTag() == .Array;
const operand = try f.resolveInst(ty_op.operand);
const writer = f.object.writer();
@@ -2565,9 +2566,11 @@ fn airStoreUndefined(f: *Function, dest_ptr: CValue) !CValue {
fn airStore(f: *Function, inst: Air.Inst.Index) !CValue {
// *a = b;
const bin_op = f.air.instructions.items(.data)[inst].bin_op;
+ const lhs_child_type = f.air.typeOf(bin_op.lhs).childType();
+ if (!lhs_child_type.hasRuntimeBitsIgnoreComptime()) return CValue.none;
+
const dest_ptr = try f.resolveInst(bin_op.lhs);
const src_val = try f.resolveInst(bin_op.rhs);
- const lhs_child_type = f.air.typeOf(bin_op.lhs).childType();
// TODO Sema should emit a different instruction when the store should
// possibly do the safety 0xaa bytes for undefined.
diff --git a/test/behavior/empty_union.zig b/test/behavior/empty_union.zig
index 3f79df0446..55dac727e8 100644
--- a/test/behavior/empty_union.zig
+++ b/test/behavior/empty_union.zig
@@ -3,7 +3,6 @@ const std = @import("std");
const expect = std.testing.expect;
test "switch on empty enum" {
- if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
const E = enum {};
@@ -29,7 +28,6 @@ test "switch on empty auto numbered tagged union" {
}
test "switch on empty tagged union" {
- if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO