summaryrefslogtreecommitdiffstats
path: root/compiler-rt/test
diff options
context:
space:
mode:
authorEvgenii Stepanov <eugenis@google.com>2019-12-19 13:38:59 -0800
committerEvgenii Stepanov <eugenis@google.com>2019-12-20 12:27:09 -0800
commit07861e955d0095f25639d84c5726c73b528567cb (patch)
treec5846f2960157e0a7783724fd6fb6d033f56478c /compiler-rt/test
parentc148e2e2ef86f53391be459752511684424f331b (diff)
downloadbcm5719-llvm-07861e955d0095f25639d84c5726c73b528567cb.tar.gz
bcm5719-llvm-07861e955d0095f25639d84c5726c73b528567cb.zip
[msan] Intercept qsort, qsort_r.
Summary: This fixes qsort-related false positives with glibc-2.27. I'm not entirely sure why they did not show up with the earlier versions; the code seems similar enough. Reviewers: vitalybuka Subscribers: #sanitizers, llvm-commits Tags: #sanitizers, #llvm Differential Revision: https://reviews.llvm.org/D71740
Diffstat (limited to 'compiler-rt/test')
-rw-r--r--compiler-rt/test/msan/qsort.cpp73
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;
+}
OpenPOWER on IntegriCloud