Skip to content

Commit 7c8bdb1

Browse files
authored
Fix UINT64_C/INT64_C macros under wasm64 (#26688)
Musl was assuming that 64-bit targets using `long` for int64_t but WebAssembly is a little different to other plaforms in that we use `long long` for int64_t for both 32-bit and 64-bit targets. See http://reviews.llvm.org/D12861. Fixes: llvm/llvm-project#192236
1 parent 3281561 commit 7c8bdb1

File tree

4 files changed

+51
-3
lines changed

4 files changed

+51
-3
lines changed

system/lib/libc/musl/include/stdint.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,13 @@ typedef uint64_t uint_least64_t;
119119
#define UINT16_C(c) c
120120
#define UINT32_C(c) c ## U
121121

122-
#if UINTPTR_MAX == UINT64_MAX
122+
// XXX EMSCRIPTEN: Use the clang-builtin macros here when available.
123+
#ifdef __UINT64_C
124+
#define INT64_C __INT64_C
125+
#define UINT64_C __UINT64_C
126+
#define INTMAX_C __INTMAX_C
127+
#define UINTMAX_C __UINTMAX_C
128+
#elif UINTPTR_MAX == UINT64_MAX
123129
#define INT64_C(c) c ## L
124130
#define UINT64_C(c) c ## UL
125131
#define INTMAX_C(c) c ## L

test/other/test_stdint_limits.64.out

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ PTRDIFF_MIN: -9223372036854775808
1010
PTRDIFF_MAX: 9223372036854775807
1111
INTPTR_MIN: -9223372036854775808
1212
INTPTR_MAX: 9223372036854775807
13+
WCHAR_MIN: -2147483648
14+
WCHAR_MAX: 2147483647
15+
WINT_MIN: 0
16+
WINT_MAX: 4294967295
1317
UINTPTR_MAX: 18446744073709551615
1418
SIZE_MAX: 18446744073709551615
1519
SSIZE_MAX: 9223372036854775807
@@ -25,3 +29,11 @@ UINT8_MAX: 255
2529
UINT16_MAX: 65535
2630
UINT32_MAX: 4294967295
2731
UINT64_MAX: 18446744073709551615
32+
INT8_C: (d) 42
33+
INT16_C: (d) 42
34+
INT32_C: (d) 42
35+
INT64_C: (lld) 42
36+
INTU8_C: (u) 42
37+
INTU16_C: (u) 42
38+
INTU32_C: (u) 42
39+
INTU64_C: (llu) 42

test/other/test_stdint_limits.c

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
#include <assert.h>
2+
#include <inttypes.h>
13
#include <limits.h>
2-
#include <stdio.h>
34
#include <stdint.h>
4-
#include <inttypes.h>
5+
#include <stdio.h>
56

67
int main () {
78
printf("INT_MIN: %d\n", INT_MIN);
@@ -22,6 +23,12 @@ int main () {
2223
printf("INTPTR_MIN: %ld\n", INTPTR_MIN);
2324
printf("INTPTR_MAX: %ld\n", INTPTR_MAX);
2425

26+
printf("WCHAR_MIN: %d\n", WCHAR_MIN);
27+
printf("WCHAR_MAX: %d\n", WCHAR_MAX);
28+
29+
printf("WINT_MIN: %u\n", WINT_MIN);
30+
printf("WINT_MAX: %u\n", WINT_MAX);
31+
2532
printf("UINTPTR_MAX: %lu\n", UINTPTR_MAX);
2633

2734
printf("SIZE_MAX: %zu\n", SIZE_MAX);
@@ -42,5 +49,16 @@ int main () {
4249
printf("UINT16_MAX: %" PRIu16 "\n", UINT16_MAX);
4350
printf("UINT32_MAX: %" PRIu32 "\n", UINT32_MAX);
4451
printf("UINT64_MAX: %" PRIu64 "\n", UINT64_MAX);
52+
53+
// Test macros for creating integer constants
54+
printf("INT8_C: (" PRId8 ") %" PRId8 "\n", INT8_C(42));
55+
printf("INT16_C: (" PRId16 ") %" PRId16 "\n", INT16_C(42));
56+
printf("INT32_C: (" PRId32 ") %" PRId32 "\n", INT32_C(42));
57+
printf("INT64_C: (" PRId64 ") %" PRId64 "\n", INT64_C(42));
58+
59+
printf("INTU8_C: (" PRIu8 ") %" PRIu8 "\n", UINT8_C(42));
60+
printf("INTU16_C: (" PRIu16 ") %" PRIu16 "\n", UINT16_C(42));
61+
printf("INTU32_C: (" PRIu32 ") %" PRIu32 "\n", UINT32_C(42));
62+
printf("INTU64_C: (" PRIu64 ") %" PRIu64 "\n", UINT64_C(42));
4563
return 0;
4664
}

test/other/test_stdint_limits.out

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ PTRDIFF_MIN: -2147483648
1010
PTRDIFF_MAX: 2147483647
1111
INTPTR_MIN: -2147483648
1212
INTPTR_MAX: 2147483647
13+
WCHAR_MIN: -2147483648
14+
WCHAR_MAX: 2147483647
15+
WINT_MIN: 0
16+
WINT_MAX: 4294967295
1317
UINTPTR_MAX: 4294967295
1418
SIZE_MAX: 4294967295
1519
SSIZE_MAX: 2147483647
@@ -25,3 +29,11 @@ UINT8_MAX: 255
2529
UINT16_MAX: 65535
2630
UINT32_MAX: 4294967295
2731
UINT64_MAX: 18446744073709551615
32+
INT8_C: (d) 42
33+
INT16_C: (d) 42
34+
INT32_C: (d) 42
35+
INT64_C: (lld) 42
36+
INTU8_C: (u) 42
37+
INTU16_C: (u) 42
38+
INTU32_C: (u) 42
39+
INTU64_C: (llu) 42

0 commit comments

Comments
 (0)