mirror of
https://github.com/ziglang/zig.git
synced 2026-02-13 04:48:20 +00:00
cbe: cast pointer switch target to int
This commit is contained in:
parent
8af5648015
commit
6310186d52
@ -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(": ");
|
||||
}
|
||||
|
||||
@ -548,7 +548,6 @@ test "switch prongs with cases with identical payload types" {
|
||||
}
|
||||
|
||||
test "switch on pointer type" {
|
||||
if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
|
||||
if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
|
||||
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user