| 1 | // RUN: %clangxx_msan -DGETC -O0 -g -xc++ %s -o %t && %run %t |
| 2 | // RUN: %clangxx_msan -DGETC -O3 -g -xc++ %s -o %t && %run %t |
| 3 | // RUN: %clang_msan -DGETC -O0 -g %s -o %t && %run %t |
| 4 | // RUN: %clang_msan -DGETC -O3 -g %s -o %t && %run %t |
| 5 | |
| 6 | // RUN: %clangxx_msan -DGETCHAR -O0 -g -xc++ %s -o %t && %run %t |
| 7 | // RUN: %clangxx_msan -DGETCHAR -O3 -g -xc++ %s -o %t && %run %t |
| 8 | // RUN: %clang_msan -DGETCHAR -O0 -g %s -o %t && %run %t |
| 9 | // RUN: %clang_msan -DGETCHAR -O3 -g %s -o %t && %run %t |
| 10 | |
| 11 | #include <assert.h> |
| 12 | #include <stdio.h> |
| 13 | #include <unistd.h> |
| 14 | |
| 15 | int main() { |
| 16 | FILE *stream = fopen(filename: "/dev/zero" , modes: "r" ); |
| 17 | flockfile (stream: stream); |
| 18 | int c; |
| 19 | #if defined(GETCHAR) |
| 20 | int res = dup2(fileno(stream), 0); |
| 21 | assert(res == 0); |
| 22 | c = getchar_unlocked(); |
| 23 | #elif defined(GETC) |
| 24 | c = getc_unlocked (stream); |
| 25 | #endif |
| 26 | funlockfile (stream: stream); |
| 27 | if (c == EOF) |
| 28 | return 1; |
| 29 | printf(format: "%c\n" , (char)c); |
| 30 | fclose(stream: stream); |
| 31 | return 0; |
| 32 | } |
| 33 | |