• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // RUN: %clang_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
2 #include <stdlib.h>
3 
foo(int * mem)4 void __attribute__((noinline)) foo(int *mem) {
5   free(mem);
6 }
7 
bar(int * mem)8 void __attribute__((noinline)) bar(int *mem) {
9   mem[0] = 42;
10 }
11 
main()12 int main() {
13   int *mem = (int*)malloc(100);
14   foo(mem);
15   bar(mem);
16   return 0;
17 }
18 
19 // CHECK: WARNING: ThreadSanitizer: heap-use-after-free
20 // CHECK:   Write of size 4 at {{.*}} by main thread:
21 // CHECK:     #0 bar
22 // CHECK:     #1 main
23 // CHECK:   Previous write of size 8 at {{.*}} by main thread:
24 // CHECK:     #0 free
25 // CHECK:     #{{1|2}} foo
26 // CHECK:     #{{2|3}} main
27