45 lines · cpp
1// RUN: %clangxx_asan -DWAIT4 -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s2// RUN: %clangxx_asan -DWAIT4 -O3 %s -o %t && not %run %t 2>&1 | FileCheck %s3 4// RUN: %clangxx_asan -DWAIT4_RUSAGE -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s5// RUN: %clangxx_asan -DWAIT4_RUSAGE -O3 %s -o %t && not %run %t 2>&1 | FileCheck %s6 7// XFAIL: android8// UNSUPPORTED: darwin9 10#include <assert.h>11#include <sys/wait.h>12#include <unistd.h>13 14int main(int argc, char **argv) {15 // This test passes on some versions of Android NDK and fails on other.16 // https://code.google.com/p/memory-sanitizer/issues/detail?id=6417 // Make it fail unconditionally on Android.18#ifdef __ANDROID__19 return 0;20#endif21 22 pid_t pid = fork();23 if (pid) { // parent24 int x[3];25 int *status = x + argc * 3;26 int res;27#if defined(WAIT4)28 res = wait4(pid, status, WNOHANG, NULL);29#elif defined(WAIT4_RUSAGE)30 struct rusage *ru = (struct rusage*)(x + argc * 3);31 int good_status;32 res = wait4(pid, &good_status, WNOHANG, ru);33#endif34 // CHECK: stack-buffer-overflow35 // CHECK: {{WRITE of size .* at 0x.* thread T0}}36 // CHECK: {{in .*wait}}37 // CHECK: {{in main .*wait4.cpp:}}38 // CHECK: is located in stack of thread T0 at offset39 // CHECK: {{in main}}40 return res == -1 ? 1 : 0;41 }42 // child43 return 0;44}45