summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEvgeniy Stepanov <eugeni.stepanov@gmail.com>2013-02-28 11:25:54 +0000
committerEvgeniy Stepanov <eugeni.stepanov@gmail.com>2013-02-28 11:25:54 +0000
commit218c582cb59c9a70e4ebdb7ebe0e9c59faec6d0c (patch)
treef365faef3942c1e929a85e46b870fe9dab3dedaa
parent00062b4498d0ec4ad0a2c52d3190671f71ea1639 (diff)
downloadbcm5719-llvm-218c582cb59c9a70e4ebdb7ebe0e9c59faec6d0c.tar.gz
bcm5719-llvm-218c582cb59c9a70e4ebdb7ebe0e9c59faec6d0c.zip
[msan] Lit tests for __attribute__((no_sanitize_memory)).
llvm-svn: 176248
-rw-r--r--compiler-rt/lib/msan/lit_tests/no_sanitize_memory.cc34
-rw-r--r--compiler-rt/lib/msan/lit_tests/no_sanitize_memory_prop.cc33
2 files changed, 67 insertions, 0 deletions
diff --git a/compiler-rt/lib/msan/lit_tests/no_sanitize_memory.cc b/compiler-rt/lib/msan/lit_tests/no_sanitize_memory.cc
new file mode 100644
index 00000000000..48afc17e35e
--- /dev/null
+++ b/compiler-rt/lib/msan/lit_tests/no_sanitize_memory.cc
@@ -0,0 +1,34 @@
+// RUN: %clangxx_msan -m64 -O0 %s -o %t && %t >%t.out 2>&1
+// RUN: %clangxx_msan -m64 -O1 %s -o %t && %t >%t.out 2>&1
+// RUN: %clangxx_msan -m64 -O2 %s -o %t && %t >%t.out 2>&1
+// RUN: %clangxx_msan -m64 -O3 %s -o %t && %t >%t.out 2>&1
+
+// RUN: %clangxx_msan -m64 -O0 %s -o %t -DCHECK_IN_F && %t >%t.out 2>&1
+// RUN: %clangxx_msan -m64 -O1 %s -o %t -DCHECK_IN_F && %t >%t.out 2>&1
+// RUN: %clangxx_msan -m64 -O2 %s -o %t -DCHECK_IN_F && %t >%t.out 2>&1
+// RUN: %clangxx_msan -m64 -O3 %s -o %t -DCHECK_IN_F && %t >%t.out 2>&1
+
+// Test that (no_sanitize_memory) functions
+// * don't check shadow values (-DCHECK_IN_F)
+// * treat all values loaded from memory as fully initialized (-UCHECK_IN_F)
+
+#include <stdlib.h>
+#include <stdio.h>
+
+__attribute__((noinline))
+__attribute__((no_sanitize_memory))
+int f(void) {
+ int x;
+ int * volatile p = &x;
+#ifdef CHECK_IN_F
+ if (*p)
+ exit(0);
+#endif
+ return *p;
+}
+
+int main(void) {
+ if (f())
+ exit(0);
+ return 0;
+}
diff --git a/compiler-rt/lib/msan/lit_tests/no_sanitize_memory_prop.cc b/compiler-rt/lib/msan/lit_tests/no_sanitize_memory_prop.cc
new file mode 100644
index 00000000000..c74ca6b89db
--- /dev/null
+++ b/compiler-rt/lib/msan/lit_tests/no_sanitize_memory_prop.cc
@@ -0,0 +1,33 @@
+// RUN: %clangxx_msan -m64 -O0 %s -o %t && %t >%t.out 2>&1
+// RUN: %clangxx_msan -m64 -O1 %s -o %t && not %t >%t.out 2>&1
+// RUN: FileCheck %s < %t.out
+// RUN: %clangxx_msan -m64 -O2 %s -o %t && not %t >%t.out 2>&1
+// RUN: FileCheck %s < %t.out
+// RUN: %clangxx_msan -m64 -O3 %s -o %t && not %t >%t.out 2>&1
+// RUN: FileCheck %s < %t.out
+
+// Test that (no_sanitize_memory) functions propagate shadow.
+
+// Note that at -O0 there is no report, because 'x' in 'f' is spilled to the
+// stack, and then loaded back as a fully initialiazed value (due to
+// no_sanitize_memory attribute).
+
+#include <stdlib.h>
+#include <stdio.h>
+
+__attribute__((noinline))
+__attribute__((no_sanitize_memory))
+int f(int x) {
+ return x;
+}
+
+int main(void) {
+ int x;
+ int * volatile p = &x;
+ int y = f(*p);
+ // CHECK: WARNING: Use of uninitialized value
+ // CHECK: {{#0 0x.* in main .*no_sanitize_memory_prop.cc:}}[[@LINE+1]]
+ if (y)
+ exit(0);
+ return 0;
+}
OpenPOWER on IntegriCloud