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 {...@@ -3894,10 +3894,14 @@ fn airSwitchBr(f: *Function, inst: Air.Inst.Index) !CValue {
3894 const writer = f.object.writer();3894 const writer = f.object.writer();
38953895
3896 try writer.writeAll("switch (");3896 try writer.writeAll("switch (");
3897 if (condition_ty.tag() == .bool) {3897 if (condition_ty.zigTypeTag() == .Bool) {
3898 try writer.writeByte('(');3898 try writer.writeByte('(');
3899 try f.renderTypecast(writer, Type.u1);3899 try f.renderTypecast(writer, Type.u1);
3900 try writer.writeByte(')');3900 try writer.writeByte(')');
3901 } else if (condition_ty.isPtrAtRuntime()) {
3902 try writer.writeByte('(');
3903 try f.renderTypecast(writer, Type.usize);
3904 try writer.writeByte(')');
3901 }3905 }
3902 try f.writeCValue(writer, condition, .Other);3906 try f.writeCValue(writer, condition, .Other);
3903 try writer.writeAll(") {");3907 try writer.writeAll(") {");
...@@ -3914,6 +3918,11 @@ fn airSwitchBr(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -3914,6 +3918,11 @@ fn airSwitchBr(f: *Function, inst: Air.Inst.Index) !CValue {
3914 for (items) |item| {3918 for (items) |item| {
3915 try f.object.indent_writer.insertNewline();3919 try f.object.indent_writer.insertNewline();
3916 try writer.writeAll("case ");3920 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 }
3917 try f.object.dg.renderValue(writer, condition_ty, f.air.value(item).?, .Other);3926 try f.object.dg.renderValue(writer, condition_ty, f.air.value(item).?, .Other);
3918 try writer.writeAll(": ");3927 try writer.writeAll(": ");
3919 }3928 }
test/behavior/switch.zig-1
...@@ -548,7 +548,6 @@ test "switch prongs with cases with identical payload types" {...@@ -548,7 +548,6 @@ test "switch prongs with cases with identical payload types" {
548}548}
549549
550test "switch on pointer type" {550test "switch on pointer type" {
551 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
552 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO551 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
553 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO552 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
554553