1 // Tests that doing dfsan_flush() while another thread is executing doesn't
3 // RUN: %clang_dfsan %s -o %t && %run %t
7 #include <sanitizer/dfsan_interface.h>
10 static unsigned char GlobalBuf
[4096];
11 static int ShutDownThread
;
12 static int StartFlush
;
14 // Access GlobalBuf continuously, causing its shadow to be touched as well.
15 // When main() calls dfsan_flush(), no segfault should be triggered.
16 static void *accessGlobalInBackground(void *Arg
) {
17 __atomic_store_n(&StartFlush
, 1, __ATOMIC_RELEASE
);
19 while (!__atomic_load_n(&ShutDownThread
, __ATOMIC_ACQUIRE
))
20 for (unsigned I
= 0; I
< sizeof(GlobalBuf
); ++I
)
28 pthread_create(&Thread
, NULL
, accessGlobalInBackground
, NULL
);
29 while (!__atomic_load_n(&StartFlush
, __ATOMIC_ACQUIRE
))
34 __atomic_store_n(&ShutDownThread
, 1, __ATOMIC_RELEASE
);
35 pthread_join(Thread
, NULL
);