aboutsummaryrefslogtreecommitdiff
path: root/src/Type.zig
diff options
context:
space:
mode:
authorfn ⌃ ⌥ <70830482+FnControlOption@users.noreply.github.com>2025-04-16 11:59:47 -0700
committermlugg <mlugg@noreply.codeberg.org>2025-11-29 21:09:08 +0100
commitbfe3317059131ab552f7583b88d6bc82609d198c (patch)
tree69fc90fcec9d34981403ff7e8c5b8d2a549b58ce /src/Type.zig
parent44e99edd7a12ea7e04fbfe53746c3af4b531f687 (diff)
downloadzig-bfe3317059131ab552f7583b88d6bc82609d198c.tar.gz
zig-bfe3317059131ab552f7583b88d6bc82609d198c.zip
Return a `usize` from `@abs` if given an `isize`
Also: - `c_ushort` for `c_short` - `c_uint` for `c_int` - `c_ulong` for `c_long` - `c_ulonglong` for `c_longlong`
Diffstat (limited to 'src/Type.zig')
-rw-r--r--src/Type.zig23
1 files changed, 16 insertions, 7 deletions
diff --git a/src/Type.zig b/src/Type.zig
index 3c13f3db94..5577d82335 100644
--- a/src/Type.zig
+++ b/src/Type.zig
@@ -3445,13 +3445,22 @@ pub fn optEuBaseType(ty: Type, zcu: *const Zcu) Type {
pub fn toUnsigned(ty: Type, pt: Zcu.PerThread) !Type {
const zcu = pt.zcu;
- return switch (ty.zigTypeTag(zcu)) {
- .int => pt.intType(.unsigned, ty.intInfo(zcu).bits),
- .vector => try pt.vectorType(.{
- .len = ty.vectorLen(zcu),
- .child = (try ty.childType(zcu).toUnsigned(pt)).toIntern(),
- }),
- else => unreachable,
+ return switch (ty.toIntern()) {
+ // zig fmt: off
+ .usize_type, .isize_type => .usize,
+ .c_ushort_type, .c_short_type => .c_ushort,
+ .c_uint_type, .c_int_type => .c_uint,
+ .c_ulong_type, .c_long_type => .c_ulong,
+ .c_ulonglong_type, .c_longlong_type => .c_ulonglong,
+ // zig fmt: on
+ else => switch (ty.zigTypeTag(zcu)) {
+ .int => pt.intType(.unsigned, ty.intInfo(zcu).bits),
+ .vector => try pt.vectorType(.{
+ .len = ty.vectorLen(zcu),
+ .child = (try ty.childType(zcu).toUnsigned(pt)).toIntern(),
+ }),
+ else => unreachable,
+ },
};
}