From 6310186d52ae4e7bccf40326a98916695192b543 Mon Sep 17 00:00:00 2001 From: Veikka Tuominen Date: Sun, 27 Nov 2022 17:16:01 +0200 Subject: cbe: cast pointer switch target to int --- src/codegen/c.zig | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'src/codegen') 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(": "); } -- cgit v1.2.3