aboutsummaryrefslogtreecommitdiff
path: root/src/codegen
diff options
context:
space:
mode:
authorVeikka Tuominen <git@vexu.eu>2022-11-27 17:16:01 +0200
committerVeikka Tuominen <git@vexu.eu>2022-11-30 15:14:33 +0200
commit6310186d52ae4e7bccf40326a98916695192b543 (patch)
tree61dc81e874474a463295b4e299a5dd7a91dca67a /src/codegen
parent8af564801551882346bd785d25f4f7bf5c374b97 (diff)
downloadzig-6310186d52ae4e7bccf40326a98916695192b543.tar.gz
zig-6310186d52ae4e7bccf40326a98916695192b543.zip
cbe: cast pointer switch target to int
Diffstat (limited to 'src/codegen')
-rw-r--r--src/codegen/c.zig11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/codegen/c.zig b/src/codegen/c.zig
index 0b9a4ef4fc..85f822d514 100644
--- a/src/codegen/c.zig
+++ b/src/codegen/c.zig
@@ -3894,10 +3894,14 @@ fn airSwitchBr(f: *Function, inst: Air.Inst.Index) !CValue {
const writer = f.object.writer();
try writer.writeAll("switch (");
- if (condition_ty.tag() == .bool) {
+ if (condition_ty.zigTypeTag() == .Bool) {
try writer.writeByte('(');
try f.renderTypecast(writer, Type.u1);
try writer.writeByte(')');
+ } else if (condition_ty.isPtrAtRuntime()) {
+ try writer.writeByte('(');
+ try f.renderTypecast(writer, Type.usize);
+ try writer.writeByte(')');
}
try f.writeCValue(writer, condition, .Other);
try writer.writeAll(") {");
@@ -3914,6 +3918,11 @@ fn airSwitchBr(f: *Function, inst: Air.Inst.Index) !CValue {
for (items) |item| {
try f.object.indent_writer.insertNewline();
try writer.writeAll("case ");
+ if (condition_ty.isPtrAtRuntime()) {
+ try writer.writeByte('(');
+ try f.renderTypecast(writer, Type.usize);
+ try writer.writeByte(')');
+ }
try f.object.dg.renderValue(writer, condition_ty, f.air.value(item).?, .Other);
try writer.writeAll(": ");
}