Skip to content

Commit 35b549e

Browse files
committed
Aligned alloc test cleaned up
1 parent cc88ee1 commit 35b549e

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

compiler-rt/test/tsan/free_race_aligned_alloc.c

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
1-
// RUN: %clang_tsan -O1 %s -o %t -undefined dynamic_lookup
1+
// RUN: %clang_tsan -O1 %s -o %t -undefined dynamic_lookup
22
// RUN: %deflake %run %t | FileCheck %s
33

44
#include "test.h"
55

6-
#ifdef __APPLE__
7-
#include <os/availability.h>
6+
#include <stdlib.h>
7+
8+
#if defined(__cplusplus) && (__cplusplus >= 201703L)
9+
#define HAVE_ALIGNED_ALLOC 1
10+
#endif
811

9-
// Allow compilation with pre-aligned-alloc SDKs
10-
API_AVAILABLE(macos(10.15), ios(13.0), tvos(13.0), watchos(6.0))
11-
void *aligned_alloc(size_t alignment, size_t size);
12+
#if defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && \
13+
__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 101500
14+
#define HAVE_ALIGNED_ALLOC 0
1215
#else
13-
#include <stdlib.h>
1416
#endif
1517

18+
1619
int *mem;
1720
pthread_mutex_t mtx;
1821

@@ -33,13 +36,13 @@ __attribute__((noinline)) void *Thread2(void *x) {
3336
}
3437

3538
int main() {
36-
if (aligned_alloc == NULL) {
37-
fprintf(stderr, "Done.\n");
38-
return 0;
39-
}
4039

4140
barrier_init(&barrier, 2);
41+
#if HAVE_ALIGNED_ALLOC
4242
mem = (int*)aligned_alloc(8, 8);
43+
#else
44+
mem = (int*)malloc(8);
45+
#endif
4346
pthread_mutex_init(&mtx, 0);
4447
pthread_t t;
4548
pthread_create(&t, NULL, Thread1, NULL);

0 commit comments

Comments
 (0)