Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tsan: add a test for stack init race
Depends on D110538. Reviewed By: melver Differential Revision: https://reviews.llvm.org/D110539
- Loading branch information
Showing
2 changed files
with
44 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s | ||
|
||
// Race with initial stack initialization: | ||
// there is no explicit second write, | ||
// but the stack variable is published unsafely. | ||
#include "test.h" | ||
|
||
long *P; | ||
|
||
void *Thread(void *a) { | ||
long X; | ||
__atomic_store_n(&P, &X, __ATOMIC_RELAXED); | ||
barrier_wait(&barrier); | ||
barrier_wait(&barrier); | ||
return 0; | ||
} | ||
|
||
int main() { | ||
barrier_init(&barrier, 2); | ||
pthread_t t; | ||
pthread_create(&t, NULL, Thread, NULL); | ||
barrier_wait(&barrier); | ||
long *p = __atomic_load_n(&P, __ATOMIC_RELAXED); | ||
*p = 42; | ||
barrier_wait(&barrier); | ||
pthread_join(t, 0); | ||
} | ||
|
||
// CHECK: WARNING: ThreadSanitizer: data race | ||
// CHECK: Write of size 8 at {{.*}} by main thread: | ||
// CHECK: #0 main | ||
// CHECK: Previous write of size 8 at {{.*}} by thread T1: | ||
// CHECK: #0 __tsan_stack_initialization | ||
// CHECK: Location is stack of thread T1 |