aboutsummaryrefslogtreecommitdiff
path: root/src/Type.zig
diff options
context:
space:
mode:
authormlugg <mlugg@mlugg.co.uk>2024-09-17 11:00:38 +0100
committermlugg <mlugg@mlugg.co.uk>2024-09-17 11:00:38 +0100
commit4650e5b9fcaa74b724a51458f5cf8952f3c734de (patch)
tree3d3b16bb86bff91c115f6778102995ac1d0e40a7 /src/Type.zig
parenta5c922179f99591d20e5b6b203c7e292692e0c28 (diff)
downloadzig-4650e5b9fcaa74b724a51458f5cf8952f3c734de.tar.gz
zig-4650e5b9fcaa74b724a51458f5cf8952f3c734de.zip
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!
Diffstat (limited to 'src/Type.zig')
-rw-r--r--src/Type.zig8
1 files changed, 2 insertions, 6 deletions
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),