Skip to content

Commit e0d840b

Browse files
FnControlOptionTechatrix
authored andcommitted
Resolve @abs as usize if given isize
1 parent 478e692 commit e0d840b

File tree

2 files changed

+21
-16
lines changed

2 files changed

+21
-16
lines changed

src/analyser/InternPool.zig

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3347,16 +3347,23 @@ pub fn intInfo(ip: *InternPool, ty: Index, target: std.Target) std.builtin.Type.
33473347
/// Asserts the type is an integer or vector of integers.
33483348
pub fn toUnsigned(ip: *InternPool, gpa: Allocator, ty: Index, target: std.Target) Allocator.Error!Index {
33493349
const tag = ip.zigTypeTag(ty) orelse unreachable;
3350-
return switch (tag) {
3351-
.int => try ip.get(gpa, .{ .int_type = .{
3352-
.signedness = .unsigned,
3353-
.bits = ip.intInfo(ty, target).bits,
3354-
} }),
3355-
.vector => try ip.get(gpa, .{ .vector_type = .{
3356-
.len = ip.vectorLen(ty),
3357-
.child = try ip.toUnsigned(gpa, ip.childType(ty), target),
3358-
} }),
3359-
else => unreachable,
3350+
return switch (ty) {
3351+
.usize_type, .isize_type => .usize_type,
3352+
.c_ushort_type, .c_short_type => .c_ushort_type,
3353+
.c_uint_type, .c_int_type => .c_uint_type,
3354+
.c_ulong_type, .c_long_type => .c_ulong_type,
3355+
.c_ulonglong_type, .c_longlong_type => .c_ulonglong_type,
3356+
else => switch (tag) {
3357+
.int => try ip.get(gpa, .{ .int_type = .{
3358+
.signedness = .unsigned,
3359+
.bits = ip.intInfo(ty, target).bits,
3360+
} }),
3361+
.vector => try ip.get(gpa, .{ .vector_type = .{
3362+
.len = ip.vectorLen(ty),
3363+
.child = try ip.toUnsigned(gpa, ip.childType(ty), target),
3364+
} }),
3365+
else => unreachable,
3366+
},
33603367
};
33613368
}
33623369

tests/analysis/builtins.zig

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -153,14 +153,12 @@ const abs_i33 = @abs(@as(i33, undefined));
153153
// ^^^^^^^ (u33)()
154154
const abs_u33 = @abs(@as(u33, undefined));
155155
// ^^^^^^^ (u33)()
156-
// TODO: type of @abs with isize depends on target; see https://github.com/ziglang/zig/pull/23587
157-
// const abs_isize = @abs(@as(isize, undefined));
158-
// // ^^^^^^^^^ (usize)()
156+
const abs_isize = @abs(@as(isize, undefined));
157+
// ^^^^^^^^^ (usize)()
159158
const abs_usize = @abs(@as(usize, undefined));
160159
// ^^^^^^^^^ (usize)()
161-
// TODO: type of @abs with c_int depends on target; see https://github.com/ziglang/zig/pull/23587
162-
// const abs_c_int = @abs(@as(c_int, undefined));
163-
// // ^^^^^^^^^ (c_uint)()
160+
const abs_c_int = @abs(@as(c_int, undefined));
161+
// ^^^^^^^^^ (c_uint)()
164162
const abs_c_uint = @abs(@as(c_uint, undefined));
165163
// ^^^^^^^^^^ (c_uint)()
166164
const abs_vector_i8 = @abs(@as(@Vector(4, i8), undefined));

0 commit comments

Comments
 (0)