authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-07-30 17:48:24-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-07-30 17:48:24-07:00
log1f95c50d9a0c4c057780d387d57ac2ac40df1720
treebf3f4560a5264f11902760dcb4ebf638b4f2e6b8
parent6e78c007dff96de98c44c52da890cdae3d6e1389

codegen: cmp lowering treats bools the same as unsigned int

fixes a crash when lowering `a == b` and they are of type bool. I'm not worried about floats; I think we will probably add separate AIR instructions for floats.

1 files changed, 6 insertions(+), 8 deletions(-)

src/codegen.zig+6-8
......@@ -2889,10 +2889,9 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
28892889 const src_mcv = try self.limitImmediateType(bin_op.rhs, i32);
28902890
28912891 try self.genX8664BinMathCode(Type.initTag(.bool), dst_mcv, src_mcv, 7, 0x38);
2892 const info = ty.intInfo(self.target.*);
2893 break :result switch (info.signedness) {
2894 .signed => MCValue{ .compare_flags_signed = op },
2895 .unsigned => MCValue{ .compare_flags_unsigned = op },
2892 break :result switch (ty.isSignedInt()) {
2893 true => MCValue{ .compare_flags_signed = op },
2894 false => MCValue{ .compare_flags_unsigned = op },
28962895 };
28972896 },
28982897 .arm, .armeb => result: {
......@@ -2934,10 +2933,9 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
29342933 // The destination register is not present in the cmp instruction
29352934 try self.genArmBinOpCode(undefined, lhs_mcv, rhs_mcv, false, .cmp_eq);
29362935
2937 const info = ty.intInfo(self.target.*);
2938 break :result switch (info.signedness) {
2939 .signed => MCValue{ .compare_flags_signed = op },
2940 .unsigned => MCValue{ .compare_flags_unsigned = op },
2936 break :result switch (ty.isSignedInt()) {
2937 true => MCValue{ .compare_flags_signed = op },
2938 false => MCValue{ .compare_flags_unsigned = op },
29412939 };
29422940 },
29432941 else => return self.fail("TODO implement cmp for {}", .{self.target.cpu.arch}),