File tree Expand file tree Collapse file tree 1 file changed +8
-6
lines changed Expand file tree Collapse file tree 1 file changed +8
-6
lines changed Original file line number Diff line number Diff line change 27
27
28
28
namespace swift {
29
29
30
- // FIXME: Use C11 aligned_alloc if available.
31
30
inline void *AlignedAlloc (size_t size, size_t align) {
32
- // posix_memalign only accepts alignments greater than sizeof(void*).
33
- //
34
- if (align < sizeof (void *))
35
- align = sizeof (void *);
36
-
37
31
#if defined(_WIN32)
38
32
void *r = _aligned_malloc (size, align);
39
33
assert (r && " _aligned_malloc failed" );
34
+ #elif __STDC_VERSION__-0 >= 201112l
35
+ // C11 supports aligned_alloc
36
+ void *r = aligned_alloc (align, size);
37
+ assert (r && " aligned_alloc failed" );
40
38
#else
39
+ // posix_memalign only accepts alignments greater than sizeof(void*).
40
+ if (align < sizeof (void *))
41
+ align = sizeof (void *);
42
+
41
43
void *r = nullptr ;
42
44
int res = posix_memalign (&r, align, size);
43
45
assert (res == 0 && " posix_memalign failed" );
You can’t perform that action at this time.
0 commit comments