aboutsummaryrefslogtreecommitdiffstats
path: root/gcc-4.9/gcc/testsuite/c-c++-common/asan/use-after-return-1.c
blob: 49933e531b92fa631120b01b3f75387b14509dcb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/* { dg-do run } */
/* { dg-set-target-env-var ASAN_OPTIONS "detect_stack_use_after_return=1" } */
/* { dg-shouldfail "asan" } */

#include <stdio.h>
#include <pthread.h>

#ifndef kSize
# define kSize 1
#endif

#ifndef UseThread
# define UseThread 0
#endif

__attribute__((noinline))
char *Ident(char *x) {
  fprintf(stderr, "1: %p\n", x);
  return x;
}

__attribute__((noinline))
char *Func1() {
  char local[kSize];
  return Ident(local);
}

__attribute__((noinline))
void Func2(char *x) {
  fprintf(stderr, "2: %p\n", x);
  *x = 1;
}

void *Thread(void *unused)  {
  Func2(Func1());
  return NULL;
}

int main(int argc, char **argv) {
#if UseThread
  pthread_t t;
  pthread_create(&t, 0, Thread, 0);
  pthread_join(t, 0);
#else
  Func2(Func1());
#endif
  return 0;
}

/* { dg-output "WRITE of size 1 at .* thread T0.*" } */
/* { dg-output "    #0.*(Func2)?.*use-after-return-1.(c:31)?.*" } */
/* { dg-output "is located in stack of thread T0 at offset.*" } */
/* { dg-output "\'local\' <== Memory access at offset 32 is inside this variable" } */