| 1 | // RUN: %clangxx_msan -std=c++11 -O0 -g %s -o %t && %run %t |
|---|---|
| 2 | // RUN: %clangxx_msan -DPOSITIVE -std=c++11 -O0 -g %s -o %t && not %run %t 2>&1 | FileCheck %s |
| 3 | |
| 4 | #include <assert.h> |
| 5 | #include <signal.h> |
| 6 | #include <sys/time.h> |
| 7 | #include <sys/wait.h> |
| 8 | #include <unistd.h> |
| 9 | |
| 10 | #include <sanitizer/msan_interface.h> |
| 11 | |
| 12 | void test_sigwait() { |
| 13 | sigset_t s; |
| 14 | #ifndef POSITIVE |
| 15 | sigemptyset(set: &s); |
| 16 | sigaddset(set: &s, SIGUSR1); |
| 17 | #endif |
| 18 | sigprocmask(SIG_BLOCK, set: &s, oset: 0); |
| 19 | // CHECK: MemorySanitizer: use-of-uninitialized-value |
| 20 | |
| 21 | if (pid_t pid = fork()) { |
| 22 | kill(pid: pid, SIGUSR1); |
| 23 | int child_stat; |
| 24 | wait(stat_loc: &child_stat); |
| 25 | _exit(status: !WIFEXITED(child_stat)); |
| 26 | } else { |
| 27 | int sig; |
| 28 | int res = sigwait(set: &s, sig: &sig); |
| 29 | assert(!res); |
| 30 | // The following checks that sig is initialized. |
| 31 | assert(sig == SIGUSR1); |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | int main(void) { |
| 36 | test_sigwait(); |
| 37 | return 0; |
| 38 | } |
| 39 |
