35 lines · cpp
1// RUN: %clangxx_asan -O0 -w %s -o %t && not %run %t 2>&1 | FileCheck %s2 3// Checks that concurrent reports will not trigger false "nested bug" reports.4// Regression test for https://github.com/google/sanitizers/issues/8585 6#include <pthread.h>7#include <stdlib.h>8#include <unistd.h>9 10static 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 20int 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(&thread[i], NULL, &start_routine, (void *)&counter);27 for (i = 0; i < n_threads; ++i)28 pthread_join(thread[i], NULL);29 return 0;30}31 32// CHECK-NOT: nested bug33// CHECK: ERROR: AddressSanitizer: stack-buffer-overflow on address34// CHECK: SUMMARY: AddressSanitizer: stack-buffer-overflow35