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 {...@@ -2889,10 +2889,9 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
2889 const src_mcv = try self.limitImmediateType(bin_op.rhs, i32);2889 const src_mcv = try self.limitImmediateType(bin_op.rhs, i32);
28902890
2891 try self.genX8664BinMathCode(Type.initTag(.bool), dst_mcv, src_mcv, 7, 0x38);2891 try self.genX8664BinMathCode(Type.initTag(.bool), dst_mcv, src_mcv, 7, 0x38);
2892 const info = ty.intInfo(self.target.*);2892 break :result switch (ty.isSignedInt()) {
2893 break :result switch (info.signedness) {2893 true => MCValue{ .compare_flags_signed = op },
2894 .signed => MCValue{ .compare_flags_signed = op },2894 false => MCValue{ .compare_flags_unsigned = op },
2895 .unsigned => MCValue{ .compare_flags_unsigned = op },
2896 };2895 };
2897 },2896 },
2898 .arm, .armeb => result: {2897 .arm, .armeb => result: {
...@@ -2934,10 +2933,9 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {...@@ -2934,10 +2933,9 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
2934 // The destination register is not present in the cmp instruction2933 // The destination register is not present in the cmp instruction
2935 try self.genArmBinOpCode(undefined, lhs_mcv, rhs_mcv, false, .cmp_eq);2934 try self.genArmBinOpCode(undefined, lhs_mcv, rhs_mcv, false, .cmp_eq);
29362935
2937 const info = ty.intInfo(self.target.*);2936 break :result switch (ty.isSignedInt()) {
2938 break :result switch (info.signedness) {2937 true => MCValue{ .compare_flags_signed = op },
2939 .signed => MCValue{ .compare_flags_signed = op },2938 false => MCValue{ .compare_flags_unsigned = op },
2940 .unsigned => MCValue{ .compare_flags_unsigned = op },
2941 };2939 };
2942 },2940 },
2943 else => return self.fail("TODO implement cmp for {}", .{self.target.cpu.arch}),2941 else => return self.fail("TODO implement cmp for {}", .{self.target.cpu.arch}),