authorgravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2021-05-17 17:41:42+02:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-05-17 17:15:22-04:00
logfe1a166589db0f2371429c93e1e1e622c19378f1
tree293a4089e582d60e9beed6275579889eab694fc5
parent5414bd48edd460ae8667c811e13aa9b5d9fab919

translate-c: Add `@truncate` where needed

Make getLimitedValue API much easier to use with zig. Fixes the compilation on 32bit hosts.

2 files changed, 6 insertions(+), 3 deletions(-)

src/clang.zig+4-1
......@@ -1,3 +1,4 @@
1const std = @import("std");
12pub const builtin = @import("builtin");
23
34pub const SourceLocation = extern struct {
......@@ -115,7 +116,9 @@ pub const APFloatBaseSemantics = extern enum {
115116};
116117
117118pub const APInt = opaque {
118 pub const getLimitedValue = ZigClangAPInt_getLimitedValue;
119 pub fn getLimitedValue(self: *const APInt, comptime T: type) T {
120 return @truncate(T, ZigClangAPInt_getLimitedValue(self, std.math.maxInt(T)));
121 }
119122 extern fn ZigClangAPInt_getLimitedValue(*const APInt, limit: u64) u64;
120123};
121124
src/translate_c.zig+2-2
......@@ -2341,7 +2341,7 @@ fn transInitListExprArray(
23412341 assert(@ptrCast(*const clang.Type, arr_type).isConstantArrayType());
23422342 const const_arr_ty = @ptrCast(*const clang.ConstantArrayType, arr_type);
23432343 const size_ap_int = const_arr_ty.getSize();
2344 const all_count = size_ap_int.getLimitedValue(math.maxInt(usize));
2344 const all_count = size_ap_int.getLimitedValue(usize);
23452345 const leftover_count = all_count - init_count;
23462346
23472347 if (all_count == 0) {
......@@ -4266,7 +4266,7 @@ fn transType(c: *Context, scope: *Scope, ty: *const clang.Type, source_loc: clan
42664266 const const_arr_ty = @ptrCast(*const clang.ConstantArrayType, ty);
42674267
42684268 const size_ap_int = const_arr_ty.getSize();
4269 const size = size_ap_int.getLimitedValue(math.maxInt(usize));
4269 const size = size_ap_int.getLimitedValue(usize);
42704270 const elem_type = try transType(c, scope, const_arr_ty.getElementType().getTypePtr(), source_loc);
42714271
42724272 return Tag.array_type.create(c.arena, .{ .len = size, .elem_type = elem_type });