| 1 | // RUN: %clangxx_asan -O0 -w %s -o %t && not %run %t 2>&1 | FileCheck %s |
|---|---|
| 2 | |
| 3 | // Checks that concurrent reports will not trigger false "nested bug" reports. |
| 4 | // Regression test for https://github.com/google/sanitizers/issues/858 |
| 5 | |
| 6 | #include <pthread.h> |
| 7 | #include <stdlib.h> |
| 8 | #include <unistd.h> |
| 9 | |
| 10 | static void *start_routine(void *arg) { |
| 11 | volatile int *counter = (volatile int *)arg; |
| 12 | char buf[8]; |
| 13 | __atomic_sub_fetch(counter, 1, __ATOMIC_SEQ_CST); |
| 14 | while (*counter) |
| 15 | ; |
| 16 | buf[0] = buf[9]; |
| 17 | return 0; |
| 18 | } |
| 19 | |
| 20 | int main(void) { |
| 21 | const int n_threads = 8; |
| 22 | int i, counter = n_threads; |
| 23 | pthread_t thread[n_threads]; |
| 24 | |
| 25 | for (i = 0; i < n_threads; ++i) |
| 26 | pthread_create(newthread: &thread[i], NULL, start_routine: &start_routine, arg: (void *)&counter); |
| 27 | for (i = 0; i < n_threads; ++i) |
| 28 | pthread_join(th: thread[i], NULL); |
| 29 | return 0; |
| 30 | } |
| 31 | |
| 32 | // CHECK-NOT: nested bug |
| 33 | // CHECK: ERROR: AddressSanitizer: stack-buffer-overflow on address |
| 34 | // CHECK: SUMMARY: AddressSanitizer: stack-buffer-overflow |
| 35 |
