Skip to content

Commit fdf4456

Browse files
authored
Add missing __LONG_MAX definition in alltypes.h (#20752)
This mirrors an upstream change in musl (emscripten-core/musl@7cc79d10) and should really have been done as part of #13006. With had report from a user who was injecting emscripten's `sysroot/include` path explicitly putting it before the clang's builtin include path which triggered `__LONG_MAX` to be undefined.
1 parent d1c731c commit fdf4456

File tree

5 files changed

+32
-11
lines changed

5 files changed

+32
-11
lines changed

system/lib/libc/musl/arch/emscripten/bits/alltypes.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@
44

55
#define __BYTE_ORDER __LITTLE_ENDIAN
66

7+
// Can't use __LONG_MAX__ here since musl's libs does pre-processor comparison
8+
// with 0x7fffffffL directly.
9+
#if __LP64__
10+
#define LONG_MAX 0x7fffffffffffffffL
11+
#else
12+
#define LONG_MAX 0x7fffffffL
13+
#endif
14+
715
#define _Addr __PTRDIFF_TYPE__
816
#define _Int64 __INT64_TYPE__
917
#define _Reg __PTRDIFF_TYPE__
Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1 @@
1-
#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
2-
|| defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
31
#define PAGE_SIZE 65536
4-
#define LONG_BIT 32
5-
#endif
6-
7-
#if __LP64__
8-
#define LONG_MAX 0x7fffffffffffffffL
9-
#else
10-
#define LONG_MAX 0x7fffffffL
11-
#endif
12-
#define LLONG_MAX 0x7fffffffffffffffLL

test/other/test_stdint_limits.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,20 @@
1+
#include <limits.h>
12
#include <stdio.h>
23
#include <stdint.h>
34

45
int main () {
6+
printf("INT_MIN: %d\n", INT_MIN);
7+
printf("INT_MAX: %d\n", INT_MAX);
8+
9+
printf("LONG_MIN: %ld\n", LONG_MIN);
10+
printf("LONG_MAX: %ld\n", LONG_MAX);
11+
12+
printf("LLONG_MIN: %lld\n", LLONG_MIN);
13+
printf("LLONG_MAX: %lld\n", LLONG_MAX);
14+
15+
printf("INTPTR_MIN: %ld\n", INTPTR_MIN);
16+
printf("INTPTR_MAX: %ld\n", INTPTR_MAX);
17+
518
printf("PTRDIFF_MIN: %ti\n", PTRDIFF_MIN);
619
printf("PTRDIFF_MAX: %ti\n", PTRDIFF_MAX);
720

test/other/test_stdint_limits.out

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
INT_MIN: -2147483648
2+
INT_MAX: 2147483647
3+
LONG_MIN: -2147483648
4+
LONG_MAX: 2147483647
5+
LLONG_MIN: -9223372036854775808
6+
LLONG_MAX: 9223372036854775807
7+
INTPTR_MIN: -2147483648
8+
INTPTR_MAX: 2147483647
19
PTRDIFF_MIN: -2147483648
210
PTRDIFF_MAX: 2147483647
311
INTPTR_MIN: -2147483648

test/test_other.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14204,3 +14204,6 @@ def test_no_pthread(self):
1420414204
self.do_runf('hello_world.c', emcc_args=['-pthread', '-no-pthread'])
1420514205
self.assertExists('hello_world.js')
1420614206
self.assertNotExists('hello_world.worker.js')
14207+
14208+
def test_sysroot_includes_first(self):
14209+
self.do_other_test('test_stdint_limits.c', emcc_args=['-std=c11', '-iwithsysroot/include'])

0 commit comments

Comments
 (0)