• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // RUN: %clangxx_asan -DWAIT -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s
2 // RUN: %clangxx_asan -DWAIT -O3 %s -o %t && not %run %t 2>&1 | FileCheck %s
3 
4 // RUN: %clangxx_asan -DWAITPID -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s
5 // RUN: %clangxx_asan -DWAITPID -O3 %s -o %t && not %run %t 2>&1 | FileCheck %s
6 
7 // RUN: %clangxx_asan -DWAIT3 -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s
8 // RUN: %clangxx_asan -DWAIT3 -O3 %s -o %t && not %run %t 2>&1 | FileCheck %s
9 
10 // RUN: %clangxx_asan -DWAIT4 -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s
11 // RUN: %clangxx_asan -DWAIT4 -O3 %s -o %t && not %run %t 2>&1 | FileCheck %s
12 
13 // RUN: %clangxx_asan -DWAIT3_RUSAGE -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s
14 // RUN: %clangxx_asan -DWAIT3_RUSAGE -O3 %s -o %t && not %run %t 2>&1 | FileCheck %s
15 
16 // RUN: %clangxx_asan -DWAIT4_RUSAGE -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s
17 // RUN: %clangxx_asan -DWAIT4_RUSAGE -O3 %s -o %t && not %run %t 2>&1 | FileCheck %s
18 
19 #include <assert.h>
20 #include <sys/wait.h>
21 #include <unistd.h>
22 
main(int argc,char ** argv)23 int main(int argc, char **argv) {
24   pid_t pid = fork();
25   if (pid) { // parent
26     int x[3];
27     int *status = x + argc * 3;
28     int res;
29 #if defined(WAIT)
30     res = wait(status);
31 #elif defined(WAITPID)
32     res = waitpid(pid, status, WNOHANG);
33 #elif defined(WAIT3)
34     res = wait3(status, WNOHANG, NULL);
35 #elif defined(WAIT4)
36     res = wait4(pid, status, WNOHANG, NULL);
37 #elif defined(WAIT3_RUSAGE) || defined(WAIT4_RUSAGE)
38     struct rusage *ru = (struct rusage*)(x + argc * 3);
39     int good_status;
40 # if defined(WAIT3_RUSAGE)
41     res = wait3(&good_status, WNOHANG, ru);
42 # elif defined(WAIT4_RUSAGE)
43     res = wait4(pid, &good_status, WNOHANG, ru);
44 # endif
45 #endif
46     // CHECK: stack-buffer-overflow
47     // CHECK: {{WRITE of size .* at 0x.* thread T0}}
48     // CHECK: {{in .*wait}}
49     // CHECK: {{in main .*wait.cc:}}
50     // CHECK: is located in stack of thread T0 at offset
51     // CHECK: {{in main}}
52     return res == -1 ? 1 : 0;
53   }
54   // child
55   return 0;
56 }
57