diff options
| author | LemonBoy <thatlemon@gmail.com> | 2021-05-17 17:41:42 +0200 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2021-05-17 17:15:22 -0400 |
| commit | fe1a166589db0f2371429c93e1e1e622c19378f1 (patch) | |
| tree | 293a4089e582d60e9beed6275579889eab694fc5 /src | |
| parent | 5414bd48edd460ae8667c811e13aa9b5d9fab919 (diff) | |
| download | zig-fe1a166589db0f2371429c93e1e1e622c19378f1.tar.gz zig-fe1a166589db0f2371429c93e1e1e622c19378f1.zip | |
translate-c: Add `@truncate` where needed
Make getLimitedValue API much easier to use with zig.
Fixes the compilation on 32bit hosts.
Diffstat (limited to 'src')
| -rw-r--r-- | src/clang.zig | 5 | ||||
| -rw-r--r-- | src/translate_c.zig | 4 |
2 files changed, 6 insertions, 3 deletions
diff --git a/src/clang.zig b/src/clang.zig index 256dbda1e1..b9e152aef4 100644 --- a/src/clang.zig +++ b/src/clang.zig @@ -1,3 +1,4 @@ +const std = @import("std"); pub const builtin = @import("builtin"); pub const SourceLocation = extern struct { @@ -115,7 +116,9 @@ pub const APFloatBaseSemantics = extern enum { }; pub const APInt = opaque { - pub const getLimitedValue = ZigClangAPInt_getLimitedValue; + pub fn getLimitedValue(self: *const APInt, comptime T: type) T { + return @truncate(T, ZigClangAPInt_getLimitedValue(self, std.math.maxInt(T))); + } extern fn ZigClangAPInt_getLimitedValue(*const APInt, limit: u64) u64; }; diff --git a/src/translate_c.zig b/src/translate_c.zig index 348e284db3..19aec279ec 100644 --- a/src/translate_c.zig +++ b/src/translate_c.zig @@ -2341,7 +2341,7 @@ fn transInitListExprArray( assert(@ptrCast(*const clang.Type, arr_type).isConstantArrayType()); const const_arr_ty = @ptrCast(*const clang.ConstantArrayType, arr_type); const size_ap_int = const_arr_ty.getSize(); - const all_count = size_ap_int.getLimitedValue(math.maxInt(usize)); + const all_count = size_ap_int.getLimitedValue(usize); const leftover_count = all_count - init_count; if (all_count == 0) { @@ -4266,7 +4266,7 @@ fn transType(c: *Context, scope: *Scope, ty: *const clang.Type, source_loc: clan const const_arr_ty = @ptrCast(*const clang.ConstantArrayType, ty); const size_ap_int = const_arr_ty.getSize(); - const size = size_ap_int.getLimitedValue(math.maxInt(usize)); + const size = size_ap_int.getLimitedValue(usize); const elem_type = try transType(c, scope, const_arr_ty.getElementType().getTypePtr(), source_loc); return Tag.array_type.create(c.arena, .{ .len = size, .elem_type = elem_type }); |
