aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2022-01-02 14:11:37 -0700
committerAndrew Kelley <andrew@ziglang.org>2022-01-02 14:11:37 -0700
commitb4d6e85a339e971829404dc1a260bde4062735f8 (patch)
tree7debe384b184d4b8c24f3d35e2ec8a32b9da8cd0 /src
parent6b14c58f63a177c26ed7ac51c25738ecb115462d (diff)
downloadzig-b4d6e85a339e971829404dc1a260bde4062735f8.tar.gz
zig-b4d6e85a339e971829404dc1a260bde4062735f8.zip
Sema: implement peer type resolution of signed and unsigned ints
This allows stage2 to build more of compiler-rt. I also changed `-%` to `-` for comptime ints in the div and mul implementations of compiler-rt. This is clearer code and also happens to work around a bug in stage2.
Diffstat (limited to 'src')
-rw-r--r--src/Sema.zig23
-rw-r--r--src/type.zig4
2 files changed, 14 insertions, 13 deletions
diff --git a/src/Sema.zig b/src/Sema.zig
index b65e88360f..42bf795bd9 100644
--- a/src/Sema.zig
+++ b/src/Sema.zig
@@ -14634,11 +14634,11 @@ fn resolvePeerTypes(
instructions: []Air.Inst.Ref,
candidate_srcs: Module.PeerTypeCandidateSrc,
) !Type {
- if (instructions.len == 0)
- return Type.initTag(.noreturn);
-
- if (instructions.len == 1)
- return sema.typeOf(instructions[0]);
+ switch (instructions.len) {
+ 0 => return Type.initTag(.noreturn),
+ 1 => return sema.typeOf(instructions[0]),
+ else => {},
+ }
const target = sema.mod.getTarget();
@@ -14668,13 +14668,14 @@ fn resolvePeerTypes(
continue;
},
.Int => {
- if (chosen_ty.isSignedInt() == candidate_ty.isSignedInt()) {
- if (chosen_ty.intInfo(target).bits < candidate_ty.intInfo(target).bits) {
- chosen = candidate;
- chosen_i = candidate_i + 1;
- }
- continue;
+ const chosen_info = chosen_ty.intInfo(target);
+ const candidate_info = candidate_ty.intInfo(target);
+
+ if (chosen_info.bits < candidate_info.bits) {
+ chosen = candidate;
+ chosen_i = candidate_i + 1;
}
+ continue;
},
.Pointer => if (chosen_ty.ptrSize() == .C) continue,
else => {},
diff --git a/src/type.zig b/src/type.zig
index 9de6bb25a8..b948093994 100644
--- a/src/type.zig
+++ b/src/type.zig
@@ -3106,9 +3106,9 @@ pub const Type = extern union {
.c_ulonglong => return .{ .signedness = .unsigned, .bits = CType.ulonglong.sizeInBits(target) },
.enum_full, .enum_nonexhaustive => ty = ty.cast(Payload.EnumFull).?.data.tag_ty,
- .enum_numbered => ty = self.castTag(.enum_numbered).?.data.tag_ty,
+ .enum_numbered => ty = ty.castTag(.enum_numbered).?.data.tag_ty,
.enum_simple => {
- const enum_obj = self.castTag(.enum_simple).?.data;
+ const enum_obj = ty.castTag(.enum_simple).?.data;
const field_count = enum_obj.fields.count();
if (field_count == 0) return .{ .signedness = .unsigned, .bits = 0 };
return .{ .signedness = .unsigned, .bits = smallestUnsignedBits(field_count - 1) };