authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-11-27 17:16:01+02:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-11-30 15:14:33+02:00
log6310186d52ae4e7bccf40326a98916695192b543
tree61dc81e874474a463295b4e299a5dd7a91dca67a
parent8af564801551882346bd785d25f4f7bf5c374b97

cbe: cast pointer switch target to int


2 files changed, 10 insertions(+), 2 deletions(-)

src/codegen/c.zig+10-1
......@@ -3894,10 +3894,14 @@ fn airSwitchBr(f: *Function, inst: Air.Inst.Index) !CValue {
38943894 const writer = f.object.writer();
38953895
38963896 try writer.writeAll("switch (");
3897 if (condition_ty.tag() == .bool) {
3897 if (condition_ty.zigTypeTag() == .Bool) {
38983898 try writer.writeByte('(');
38993899 try f.renderTypecast(writer, Type.u1);
39003900 try writer.writeByte(')');
3901 } else if (condition_ty.isPtrAtRuntime()) {
3902 try writer.writeByte('(');
3903 try f.renderTypecast(writer, Type.usize);
3904 try writer.writeByte(')');
39013905 }
39023906 try f.writeCValue(writer, condition, .Other);
39033907 try writer.writeAll(") {");
......@@ -3914,6 +3918,11 @@ fn airSwitchBr(f: *Function, inst: Air.Inst.Index) !CValue {
39143918 for (items) |item| {
39153919 try f.object.indent_writer.insertNewline();
39163920 try writer.writeAll("case ");
3921 if (condition_ty.isPtrAtRuntime()) {
3922 try writer.writeByte('(');
3923 try f.renderTypecast(writer, Type.usize);
3924 try writer.writeByte(')');
3925 }
39173926 try f.object.dg.renderValue(writer, condition_ty, f.air.value(item).?, .Other);
39183927 try writer.writeAll(": ");
39193928 }
test/behavior/switch.zig-1
......@@ -548,7 +548,6 @@ test "switch prongs with cases with identical payload types" {
548548}
549549
550550test "switch on pointer type" {
551 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
552551 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
553552 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
554553