summaryrefslogtreecommitdiff
path: root/test/msan/getc_unlocked.c
diff options
context:
space:
mode:
Diffstat (limited to 'test/msan/getc_unlocked.c')
-rw-r--r--test/msan/getc_unlocked.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/test/msan/getc_unlocked.c b/test/msan/getc_unlocked.c
new file mode 100644
index 000000000..805806ffb
--- /dev/null
+++ b/test/msan/getc_unlocked.c
@@ -0,0 +1,32 @@
+// RUN: %clangxx_msan -DGETC -m64 -O0 -g -xc++ %s -o %t && %t
+// RUN: %clangxx_msan -DGETC -m64 -O3 -g -xc++ %s -o %t && %t
+// RUN: %clang_msan -DGETC -m64 -O0 -g %s -o %t && %t
+// RUN: %clang_msan -DGETC -m64 -O3 -g %s -o %t && %t
+
+// RUN: %clangxx_msan -DGETCHAR -m64 -O0 -g -xc++ %s -o %t && %t
+// RUN: %clangxx_msan -DGETCHAR -m64 -O3 -g -xc++ %s -o %t && %t
+// RUN: %clang_msan -DGETCHAR -m64 -O0 -g %s -o %t && %t
+// RUN: %clang_msan -DGETCHAR -m64 -O3 -g %s -o %t && %t
+
+#include <assert.h>
+#include <stdio.h>
+#include <unistd.h>
+
+int main() {
+ FILE *stream = fopen("/dev/zero", "r");
+ flockfile (stream);
+ int c;
+#if defined(GETCHAR)
+ int res = dup2(fileno(stream), 0);
+ assert(res == 0);
+ c = getchar_unlocked();
+#elif defined(GETC)
+ c = getc_unlocked (stream);
+#endif
+ funlockfile (stream);
+ if (c == EOF)
+ return 1;
+ printf("%c\n", (char)c);
+ fclose(stream);
+ return 0;
+}