From d45a33f89211950818e53caad9ee44efeaa9b9e3 Mon Sep 17 00:00:00 2001 From: Sam Clegg Date: Wed, 15 Apr 2026 09:13:14 -0700 Subject: [PATCH] Fix UINT64_C/INT64_C macros under wasm64 Fixes: https://github.com/llvm/llvm-project/issues/192236 --- system/lib/libc/musl/include/stdint.h | 8 +++++++- test/other/test_stdint_limits.64.out | 12 ++++++++++++ test/other/test_stdint_limits.c | 22 ++++++++++++++++++++-- test/other/test_stdint_limits.out | 12 ++++++++++++ 4 files changed, 51 insertions(+), 3 deletions(-) diff --git a/system/lib/libc/musl/include/stdint.h b/system/lib/libc/musl/include/stdint.h index 9154e565e5387..cb1991b44502c 100644 --- a/system/lib/libc/musl/include/stdint.h +++ b/system/lib/libc/musl/include/stdint.h @@ -119,7 +119,13 @@ typedef uint64_t uint_least64_t; #define UINT16_C(c) c #define UINT32_C(c) c ## U -#if UINTPTR_MAX == UINT64_MAX +// XXX EMSCRIPTEN: Use the clang-builtin macros here when available. +#ifdef __UINT64_C +#define INT64_C __INT64_C +#define UINT64_C __UINT64_C +#define INTMAX_C __INTMAX_C +#define UINTMAX_C __UINTMAX_C +#elif UINTPTR_MAX == UINT64_MAX #define INT64_C(c) c ## L #define UINT64_C(c) c ## UL #define INTMAX_C(c) c ## L diff --git a/test/other/test_stdint_limits.64.out b/test/other/test_stdint_limits.64.out index db1c41003c4c7..9b760133b633d 100644 --- a/test/other/test_stdint_limits.64.out +++ b/test/other/test_stdint_limits.64.out @@ -10,6 +10,10 @@ PTRDIFF_MIN: -9223372036854775808 PTRDIFF_MAX: 9223372036854775807 INTPTR_MIN: -9223372036854775808 INTPTR_MAX: 9223372036854775807 +WCHAR_MIN: -2147483648 +WCHAR_MAX: 2147483647 +WINT_MIN: 0 +WINT_MAX: 4294967295 UINTPTR_MAX: 18446744073709551615 SIZE_MAX: 18446744073709551615 SSIZE_MAX: 9223372036854775807 @@ -25,3 +29,11 @@ UINT8_MAX: 255 UINT16_MAX: 65535 UINT32_MAX: 4294967295 UINT64_MAX: 18446744073709551615 +INT8_C: (d) 42 +INT16_C: (d) 42 +INT32_C: (d) 42 +INT64_C: (lld) 42 +INTU8_C: (u) 42 +INTU16_C: (u) 42 +INTU32_C: (u) 42 +INTU64_C: (llu) 42 diff --git a/test/other/test_stdint_limits.c b/test/other/test_stdint_limits.c index 4ac42895fc5db..d44aac591b315 100644 --- a/test/other/test_stdint_limits.c +++ b/test/other/test_stdint_limits.c @@ -1,7 +1,8 @@ +#include +#include #include -#include #include -#include +#include int main () { printf("INT_MIN: %d\n", INT_MIN); @@ -22,6 +23,12 @@ int main () { printf("INTPTR_MIN: %ld\n", INTPTR_MIN); printf("INTPTR_MAX: %ld\n", INTPTR_MAX); + printf("WCHAR_MIN: %d\n", WCHAR_MIN); + printf("WCHAR_MAX: %d\n", WCHAR_MAX); + + printf("WINT_MIN: %u\n", WINT_MIN); + printf("WINT_MAX: %u\n", WINT_MAX); + printf("UINTPTR_MAX: %lu\n", UINTPTR_MAX); printf("SIZE_MAX: %zu\n", SIZE_MAX); @@ -42,5 +49,16 @@ int main () { printf("UINT16_MAX: %" PRIu16 "\n", UINT16_MAX); printf("UINT32_MAX: %" PRIu32 "\n", UINT32_MAX); printf("UINT64_MAX: %" PRIu64 "\n", UINT64_MAX); + + // Test macros for creating integer constants + printf("INT8_C: (" PRId8 ") %" PRId8 "\n", INT8_C(42)); + printf("INT16_C: (" PRId16 ") %" PRId16 "\n", INT16_C(42)); + printf("INT32_C: (" PRId32 ") %" PRId32 "\n", INT32_C(42)); + printf("INT64_C: (" PRId64 ") %" PRId64 "\n", INT64_C(42)); + + printf("INTU8_C: (" PRIu8 ") %" PRIu8 "\n", UINT8_C(42)); + printf("INTU16_C: (" PRIu16 ") %" PRIu16 "\n", UINT16_C(42)); + printf("INTU32_C: (" PRIu32 ") %" PRIu32 "\n", UINT32_C(42)); + printf("INTU64_C: (" PRIu64 ") %" PRIu64 "\n", UINT64_C(42)); return 0; } diff --git a/test/other/test_stdint_limits.out b/test/other/test_stdint_limits.out index 30eb340537bdb..d2a9c6852eb1e 100644 --- a/test/other/test_stdint_limits.out +++ b/test/other/test_stdint_limits.out @@ -10,6 +10,10 @@ PTRDIFF_MIN: -2147483648 PTRDIFF_MAX: 2147483647 INTPTR_MIN: -2147483648 INTPTR_MAX: 2147483647 +WCHAR_MIN: -2147483648 +WCHAR_MAX: 2147483647 +WINT_MIN: 0 +WINT_MAX: 4294967295 UINTPTR_MAX: 4294967295 SIZE_MAX: 4294967295 SSIZE_MAX: 2147483647 @@ -25,3 +29,11 @@ UINT8_MAX: 255 UINT16_MAX: 65535 UINT32_MAX: 4294967295 UINT64_MAX: 18446744073709551615 +INT8_C: (d) 42 +INT16_C: (d) 42 +INT32_C: (d) 42 +INT64_C: (lld) 42 +INTU8_C: (u) 42 +INTU16_C: (u) 42 +INTU32_C: (u) 42 +INTU64_C: (llu) 42