aboutsummaryrefslogtreecommitdiffstats
path: root/gcc-4.9/gcc/testsuite/c-c++-common/tsan/free_race.c
blob: 258f7b7420dfe0b6685839a7b070b56e3aab5b92 (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
/* { dg-shouldfail "tsan" } */

#include <stdlib.h>

void __attribute__((noinline)) foo(int *mem) {
  free(mem);
}

void __attribute__((noinline)) bar(int *mem) {
  mem[0] = 42;
}

int main() {
  int *mem =(int*)malloc (100);
  foo(mem);
  bar(mem);
  return 0;
}

/* { dg-output "WARNING: ThreadSanitizer: heap-use-after-free.*(\n|\r\n|\r)" } */
/* { dg-output "  Write of size 4 at.* by main thread:(\n|\r\n|\r)" } */
/* { dg-output "    #0 bar.*(\n|\r\n|\r)" } */
/* { dg-output "    #1 main.*(\n|\r\n|\r)" } */
/* { dg-output "  Previous write of size 8 at.* by main thread:(\n|\r\n|\r)" } */
/* { dg-output "    #0 free.*(\n|\r\n|\r)" } */
/* { dg-output "    #\(1|2\) foo.*(\n|\r\n|\r)" } */
/* { dg-output "    #\(2|3\) main.*(\n|\r\n|\r)" } */