Skip to content

Commit 64d1aba

Browse files
authored
Add test for __BIGGEST_ALIGNMENT__ and use it over hardcoded constants. NFC (#19728)
1 parent b93f9de commit 64d1aba

File tree

3 files changed

+17
-14
lines changed

3 files changed

+17
-14
lines changed

system/lib/pthread/pthread_create.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#include <emscripten/heap.h>
1818
#include <emscripten/threading.h>
1919

20-
#define STACK_ALIGN 16
20+
#define STACK_ALIGN __BIGGEST_ALIGNMENT__
2121
#define TSD_ALIGN (sizeof(void*))
2222

2323
// Comment this line to enable tracing of thread creation and destruction:

system/lib/wasm_worker/library_wasm_worker.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
#define ROUND_UP(x, ALIGNMENT) (((x)+ALIGNMENT-1)&-ALIGNMENT)
1717
#define SBRK_ALIGN (__alignof__(max_align_t))
18-
#define STACK_ALIGN 16
18+
#define STACK_ALIGN __BIGGEST_ALIGNMENT__
1919

2020
// Options:
2121
// #define STACK_OVERFLOW_CHECK 0/1/2 : set to the current stack overflow check mode

test/core/test_core_types.c

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@
8181
#error EMSCRIPTEN is not defined
8282
#endif
8383

84+
#include <stdalign.h>
8485
#include <stdint.h>
8586
#include <stddef.h>
8687
#include <string.h>
@@ -91,22 +92,24 @@
9192

9293
int main() {
9394
#if __wasm64__
94-
assert(sizeof(void*) == 8);
95-
assert(sizeof(long) == 8);
96-
assert(sizeof(intptr_t) == 8);
97-
assert(sizeof(size_t) == 8);
98-
assert(sizeof(ptrdiff_t) == 8);
95+
assert(__SIZEOF_POINTER__ == 8);
9996
#else
100-
assert(sizeof(void*) == 4);
101-
assert(sizeof(long) == 4);
102-
assert(sizeof(intptr_t) == 4);
103-
assert(sizeof(size_t) == 4);
104-
assert(sizeof(ptrdiff_t) == 4);
97+
assert(__SIZEOF_POINTER__ == 4);
10598
#endif
99+
assert(sizeof(void*) == __SIZEOF_POINTER__);
100+
assert(sizeof(long) == __SIZEOF_POINTER__);
101+
assert(sizeof(intptr_t) == __SIZEOF_POINTER__);
102+
assert(sizeof(size_t) == __SIZEOF_POINTER__);
103+
assert(sizeof(ptrdiff_t) == __SIZEOF_POINTER__);
106104
assert(sizeof(intmax_t) == 8);
107-
assert(__alignof(double) == 8);
105+
assert(alignof(double) == 8);
108106
assert(sizeof(long double) == 16);
109-
assert(__alignof(long double) == 8);
107+
assert(alignof(long double) == 8);
108+
assert(alignof(max_align_t) == 8);
109+
// __BIGGEST_ALIGNMENT__ corresponds to the default stack alignment
110+
// used by llvm. Unlike `alignof(max_align_t)` it includes SIMD types.
111+
// We use this in emscripten as our default stack alignment.
112+
assert(__BIGGEST_ALIGNMENT__ == 16);
110113
assert(__FLT_EVAL_METHOD__ == 0);
111114
assert(strcmp(STRINGIZE(__USER_LABEL_PREFIX__), "") == 0);
112115
return 0;

0 commit comments

Comments
 (0)