1 // Tests that doing dfsan_flush() while another thread is executing doesn't
3 // RUN: %clang_dfsan %s -o %t && %run %t
5 // REQUIRES: x86_64-target-arch
9 #include <sanitizer/dfsan_interface.h>
12 static unsigned char GlobalBuf
[4096];
13 static int ShutDownThread
;
14 static int StartFlush
;
16 // Access GlobalBuf continuously, causing its shadow to be touched as well.
17 // When main() calls dfsan_flush(), no segfault should be triggered.
18 static void *accessGlobalInBackground(void *Arg
) {
19 __atomic_store_n(&StartFlush
, 1, __ATOMIC_RELEASE
);
21 while (!__atomic_load_n(&ShutDownThread
, __ATOMIC_ACQUIRE
))
22 for (unsigned I
= 0; I
< sizeof(GlobalBuf
); ++I
)
30 pthread_create(&Thread
, NULL
, accessGlobalInBackground
, NULL
);
31 while (!__atomic_load_n(&StartFlush
, __ATOMIC_ACQUIRE
))
36 __atomic_store_n(&ShutDownThread
, 1, __ATOMIC_RELEASE
);
37 pthread_join(Thread
, NULL
);