authorgravatar for evan@lagerdata.comEvan Haas <evan@lagerdata.com> 2022-08-30 20:45:42-07:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-08-31 15:52:53+03:00
logfdb88708527742e450e4c566024d9d50ce61dd8d
tree1a35982af5dd47599044afcd1f1e722bcda09fee
parentb45387f20e3abad052a11df55d2cd7bab099e5c3

translate-c: promote large integer macros to unsigned long long if necessary

Closes #10793 Co-authored-by: Veikka Tuominen <git@vexu.eu>

3 files changed, 7 insertions(+), 1 deletions(-)

lib/std/zig/c_translation.zig+1-1
......@@ -268,7 +268,7 @@ test "sizeof" {
268268pub const CIntLiteralRadix = enum { decimal, octal, hexadecimal };
269269
270270fn PromoteIntLiteralReturnType(comptime SuffixType: type, comptime number: comptime_int, comptime radix: CIntLiteralRadix) type {
271 const signed_decimal = [_]type{ c_int, c_long, c_longlong };
271 const signed_decimal = [_]type{ c_int, c_long, c_longlong, c_ulonglong };
272272 const signed_oct_hex = [_]type{ c_int, c_uint, c_long, c_ulong, c_longlong, c_ulonglong };
273273 const unsigned = [_]type{ c_uint, c_ulong, c_ulonglong };
274274
test/behavior/translate_c_macros.h+2
......@@ -48,3 +48,5 @@ typedef _Bool uintptr_t;
4848
4949#define CAST_TO_BOOL(X) (_Bool)(X)
5050#define CAST_TO_UINTPTR(X) (uintptr_t)(X)
51
52#define LARGE_INT 18446744073709550592
test/behavior/translate_c_macros.zig+4
......@@ -113,3 +113,7 @@ test "cast functions" {
113113 try expectEqual(true, h.CAST_TO_BOOL(S.foo));
114114 try expect(h.CAST_TO_UINTPTR(S.foo) != 0);
115115}
116
117test "large integer macro" {
118 try expectEqual(@as(c_ulonglong, 18446744073709550592), h.LARGE_INT);
119}