summaryrefslogtreecommitdiff
path: root/test/msan/getc_unlocked.c
diff options
context:
space:
mode:
authorEvgeniy Stepanov <eugeni.stepanov@gmail.com>2014-04-25 13:26:21 +0000
committerEvgeniy Stepanov <eugeni.stepanov@gmail.com>2014-04-25 13:26:21 +0000
commitb8cb1d665c2d0b7715b65c977faf0c9ed0db8c59 (patch)
tree741ce921a1f1d266883e2246c844f19b8ab3794e /test/msan/getc_unlocked.c
parenta15bc5aa2127258cd1982b5e97fbceaf8abe657b (diff)
downloadcompiler-rt-b8cb1d665c2d0b7715b65c977faf0c9ed0db8c59.tar.gz
[sanitizer] Intercept a bunch of stdio calls.
Add move fopen/freopen interceptors from TSan to common. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@207224 91177308-0d34-0410-b5e6-96231b3b80d8
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;
+}