diff options
author | Evgeniy Stepanov <eugeni.stepanov@gmail.com> | 2014-04-25 13:26:21 +0000 |
---|---|---|
committer | Evgeniy Stepanov <eugeni.stepanov@gmail.com> | 2014-04-25 13:26:21 +0000 |
commit | b8cb1d665c2d0b7715b65c977faf0c9ed0db8c59 (patch) | |
tree | 741ce921a1f1d266883e2246c844f19b8ab3794e /test/msan | |
parent | a15bc5aa2127258cd1982b5e97fbceaf8abe657b (diff) | |
download | compiler-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')
-rw-r--r-- | test/msan/getc_unlocked.c | 32 | ||||
-rw-r--r-- | test/msan/open_memstream.cc | 18 |
2 files changed, 50 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; +} diff --git a/test/msan/open_memstream.cc b/test/msan/open_memstream.cc new file mode 100644 index 000000000..af3f795d9 --- /dev/null +++ b/test/msan/open_memstream.cc @@ -0,0 +1,18 @@ +// RUN: %clangxx_msan -m64 -O0 -g -xc++ %s -o %t && %t +// RUN: %clangxx_msan -m64 -O3 -g -xc++ %s -o %t && %t + +#include <stdio.h> +#include <stdlib.h> + +int main(void) { + char *buf; + size_t buf_len = 42; + FILE *fp = open_memstream(&buf, &buf_len); + fprintf(fp, "hello"); + fflush(fp); + printf("buf_len = %zu\n", buf_len); + for (int j = 0; j < buf_len; j++) { + printf("buf[%d] = %c\n", j, buf[j]); + } + return 0; +} |