From 4650e5b9fcaa74b724a51458f5cf8952f3c734de Mon Sep 17 00:00:00 2001 From: mlugg Date: Tue, 17 Sep 2024 11:00:38 +0100 Subject: Sema: clean up cmpNumeric There is one minor language change here, which is that comparisons of the form `comptime_inf < runtime_f32` have their results comptime-known. This is consistent with comparisons against comptime NaN for instance, which are always comptime known. A corresponding behavior test is added. This fixes a bug with int comparison elision which my previous commit somehow triggered. `Sema.compareIntsOnlyPossibleResult` is much cleaner now! --- src/Type.zig | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'src/Type.zig') diff --git a/src/Type.zig b/src/Type.zig index 2048fc852b..0dfd12cb35 100644 --- a/src/Type.zig +++ b/src/Type.zig @@ -3040,8 +3040,7 @@ pub fn minInt(ty: Type, pt: Zcu.PerThread, dest_ty: Type) !Value { pub fn minIntScalar(ty: Type, pt: Zcu.PerThread, dest_ty: Type) !Value { const zcu = pt.zcu; const info = ty.intInfo(zcu); - if (info.signedness == .unsigned) return pt.intValue(dest_ty, 0); - if (info.bits == 0) return pt.intValue(dest_ty, -1); + if (info.signedness == .unsigned or info.bits == 0) return pt.intValue(dest_ty, 0); if (std.math.cast(u6, info.bits - 1)) |shift| { const n = @as(i64, std.math.minInt(i64)) >> (63 - shift); @@ -3072,10 +3071,7 @@ pub fn maxIntScalar(ty: Type, pt: Zcu.PerThread, dest_ty: Type) !Value { const info = ty.intInfo(pt.zcu); switch (info.bits) { - 0 => return switch (info.signedness) { - .signed => try pt.intValue(dest_ty, -1), - .unsigned => try pt.intValue(dest_ty, 0), - }, + 0 => return pt.intValue(dest_ty, 0), 1 => return switch (info.signedness) { .signed => try pt.intValue(dest_ty, 0), .unsigned => try pt.intValue(dest_ty, 1), -- cgit v1.2.3