aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEvan Haas <evan@lagerdata.com>2022-08-30 20:45:42 -0700
committerVeikka Tuominen <git@vexu.eu>2022-08-31 15:52:53 +0300
commitfdb88708527742e450e4c566024d9d50ce61dd8d (patch)
tree1a35982af5dd47599044afcd1f1e722bcda09fee
parentb45387f20e3abad052a11df55d2cd7bab099e5c3 (diff)
downloadzig-fdb88708527742e450e4c566024d9d50ce61dd8d.tar.gz
zig-fdb88708527742e450e4c566024d9d50ce61dd8d.zip
translate-c: promote large integer macros to unsigned long long if necessary
Closes #10793 Co-authored-by: Veikka Tuominen <git@vexu.eu>
-rw-r--r--lib/std/zig/c_translation.zig2
-rw-r--r--test/behavior/translate_c_macros.h2
-rw-r--r--test/behavior/translate_c_macros.zig4
3 files changed, 7 insertions, 1 deletions
diff --git a/lib/std/zig/c_translation.zig b/lib/std/zig/c_translation.zig
index 348e3a7133..6847a92eae 100644
--- a/lib/std/zig/c_translation.zig
+++ b/lib/std/zig/c_translation.zig
@@ -268,7 +268,7 @@ test "sizeof" {
pub const CIntLiteralRadix = enum { decimal, octal, hexadecimal };
fn PromoteIntLiteralReturnType(comptime SuffixType: type, comptime number: comptime_int, comptime radix: CIntLiteralRadix) type {
- const signed_decimal = [_]type{ c_int, c_long, c_longlong };
+ const signed_decimal = [_]type{ c_int, c_long, c_longlong, c_ulonglong };
const signed_oct_hex = [_]type{ c_int, c_uint, c_long, c_ulong, c_longlong, c_ulonglong };
const unsigned = [_]type{ c_uint, c_ulong, c_ulonglong };
diff --git a/test/behavior/translate_c_macros.h b/test/behavior/translate_c_macros.h
index 526ab32abc..222a7ded6c 100644
--- a/test/behavior/translate_c_macros.h
+++ b/test/behavior/translate_c_macros.h
@@ -48,3 +48,5 @@ typedef _Bool uintptr_t;
#define CAST_TO_BOOL(X) (_Bool)(X)
#define CAST_TO_UINTPTR(X) (uintptr_t)(X)
+
+#define LARGE_INT 18446744073709550592
diff --git a/test/behavior/translate_c_macros.zig b/test/behavior/translate_c_macros.zig
index 705c60aa4e..a23907c88f 100644
--- a/test/behavior/translate_c_macros.zig
+++ b/test/behavior/translate_c_macros.zig
@@ -113,3 +113,7 @@ test "cast functions" {
try expectEqual(true, h.CAST_TO_BOOL(S.foo));
try expect(h.CAST_TO_UINTPTR(S.foo) != 0);
}
+
+test "large integer macro" {
+ try expectEqual(@as(c_ulonglong, 18446744073709550592), h.LARGE_INT);
+}