[hwasan] deflake a test
authorKostya Serebryany <kcc@google.com>
Wed, 5 Sep 2018 16:09:53 +0000 (16:09 +0000)
committerKostya Serebryany <kcc@google.com>
Wed, 5 Sep 2018 16:09:53 +0000 (16:09 +0000)
llvm-svn: 341480

compiler-rt/test/hwasan/TestCases/thread-uaf.c

index 200b35a..33cea10 100644 (file)
@@ -19,7 +19,6 @@ void *Allocate(void *arg) {
   return NULL;
 }
 void *Deallocate(void *arg) {
-  while (__sync_fetch_and_add(&state, 0) != 1) {}
   free(x);
   __sync_fetch_and_add(&state, 1);
   while (__sync_fetch_and_add(&state, 0) != 3) {}
@@ -27,7 +26,6 @@ void *Deallocate(void *arg) {
 }
 
 void *Use(void *arg) {
-  while (__sync_fetch_and_add(&state, 0) != 2) {}
   x[5] = 42;
   // CHECK: ERROR: HWAddressSanitizer: tag-mismatch on address
   // CHECK: WRITE of size 1 {{.*}} in thread T3
@@ -47,7 +45,9 @@ int main() {
   pthread_t t1, t2, t3;
 
   pthread_create(&t1, NULL, Allocate, NULL);
+  while (__sync_fetch_and_add(&state, 0) != 1) {}
   pthread_create(&t2, NULL, Deallocate, NULL);
+  while (__sync_fetch_and_add(&state, 0) != 2) {}
   pthread_create(&t3, NULL, Use, NULL);
 
   pthread_join(t1, NULL);