blob: 4931c2147e79d98795b4777369c82a492fd05f35 [file] [log] [blame]
/* { dg-do run { target pthread_h } } */
/* { dg-skip-if "no pthread_barrier" { *-*-darwin* } } */
/* { dg-shouldfail "asan" } */
/* { dg-set-target-env-var ASAN_OPTIONS "detect_invalid_pointer_pairs=2:halt_on_error=1" } */
/* { dg-options "-fsanitize=address,pointer-subtract" } */
/* { dg-additional-options "-pthread" { target pthread } } */
#include <unistd.h>
#include <pthread.h>
char *pointer;
pthread_barrier_t bar;
void *
thread_main (void *n)
{
char local;
(void) n;
pointer = &local;
pthread_barrier_wait (&bar);
pthread_barrier_wait (&bar);
return 0;
}
int
main ()
{
pthread_t thread;
pthread_barrier_init (&bar, NULL, 2);
pthread_create (&thread, NULL, thread_main, NULL);
pthread_barrier_wait (&bar);
char local;
char *parent_pointer = &local;
/* { dg-output "ERROR: AddressSanitizer: invalid-pointer-pair" } */
volatile __PTRDIFF_TYPE__ r = parent_pointer - pointer;
pthread_barrier_wait (&bar);
pthread_join (thread, NULL);
pthread_barrier_destroy (&bar);
return 0;
}