diff options
author | Reid Kleckner <rnk@google.com> | 2019-12-27 11:29:00 -0800 |
---|---|---|
committer | Reid Kleckner <rnk@google.com> | 2019-12-27 11:29:00 -0800 |
commit | ef7a659c21fb28b20a49912c2bc47b7af6637f85 (patch) | |
tree | 344c33aeb42af2a08efa41f3fef68a422ba2c544 /compiler-rt/test | |
parent | 8fcce5ac73d49981656d9126e6c88391c1f6bf01 (diff) | |
download | bcm5719-llvm-ef7a659c21fb28b20a49912c2bc47b7af6637f85.tar.gz bcm5719-llvm-ef7a659c21fb28b20a49912c2bc47b7af6637f85.zip |
Reland "[msan] Intercept qsort, qsort_r."
This reverts commit 8fcce5ac73d49981656d9126e6c88391c1f6bf01.
I spoke too soon, the revert does not actually cause the startup crash
to go away.
Diffstat (limited to 'compiler-rt/test')
-rw-r--r-- | compiler-rt/test/msan/qsort.cpp | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/compiler-rt/test/msan/qsort.cpp b/compiler-rt/test/msan/qsort.cpp new file mode 100644 index 00000000000..eb869701186 --- /dev/null +++ b/compiler-rt/test/msan/qsort.cpp @@ -0,0 +1,73 @@ +// RUN: %clangxx_msan -O0 -g %s -o %t && %run %t + +#include <assert.h> +#include <errno.h> +#include <glob.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include <sanitizer/msan_interface.h> + +constexpr size_t kSize1 = 27; +constexpr size_t kSize2 = 7; + +bool seen2; + +void dummy(long a, long b, long c, long d, long e) {} + +void poison_stack_and_param() { + char x[10000]; + int y; + dummy(y, y, y, y, y); +} + +__attribute__((always_inline)) int cmp(long a, long b) { + if (a < b) + return -1; + else if (a > b) + return 1; + else + return 0; +} + +int compar2(const void *a, const void *b) { + assert(a); + assert(b); + __msan_check_mem_is_initialized(a, sizeof(long)); + __msan_check_mem_is_initialized(b, sizeof(long)); + seen2 = true; + poison_stack_and_param(); + return cmp(*(long *)a, *(long *)b); +} + +int compar1(const void *a, const void *b) { + assert(a); + assert(b); + __msan_check_mem_is_initialized(a, sizeof(long)); + __msan_check_mem_is_initialized(b, sizeof(long)); + + long *p = new long[kSize2]; + // kind of random + for (int i = 0; i < kSize2; ++i) + p[i] = i * 2 + (i % 3 - 1) * 3; + qsort(p, kSize1, sizeof(long), compar2); + __msan_check_mem_is_initialized(p, sizeof(long) * kSize2); + delete[] p; + + poison_stack_and_param(); + return cmp(*(long *)a, *(long *)b); +} + +int main(int argc, char *argv[]) { + long *p = new long[kSize1]; + // kind of random + for (int i = 0; i < kSize1; ++i) + p[i] = i * 2 + (i % 3 - 1) * 3; + poison_stack_and_param(); + qsort(p, kSize1, sizeof(long), compar1); + __msan_check_mem_is_initialized(p, sizeof(long) * kSize1); + assert(seen2); + delete[] p; + return 0; +} |