aboutsummaryrefslogtreecommitdiff
path: root/test/asan/TestCases/speculative_load.cc
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2015-12-30 11:52:19 +0000
committerDimitry Andric <dim@FreeBSD.org>2015-12-30 11:52:19 +0000
commit5c909fa013fc285f010a95e8d387e0ef3412da9c (patch)
tree1059d068ad281f4776ff44cd414574f99a460023 /test/asan/TestCases/speculative_load.cc
parentf31bcc68c72371a2bf63aead9f3373a1ff2053b6 (diff)
downloadsrc-5c909fa013fc285f010a95e8d387e0ef3412da9c.tar.gz
src-5c909fa013fc285f010a95e8d387e0ef3412da9c.zip
Vendor import of compiler-rt trunk r256633:vendor/compiler-rt/compiler-rt-trunk-r256633
Notes
Notes: svn path=/vendor/compiler-rt/dist/; revision=292925 svn path=/vendor/compiler-rt/compiler-rt-trunk-r256633/; revision=292926; tag=vendor/compiler-rt/compiler-rt-trunk-r256633
Diffstat (limited to 'test/asan/TestCases/speculative_load.cc')
-rw-r--r--test/asan/TestCases/speculative_load.cc50
1 files changed, 50 insertions, 0 deletions
diff --git a/test/asan/TestCases/speculative_load.cc b/test/asan/TestCases/speculative_load.cc
new file mode 100644
index 000000000000..2409d7a5eee3
--- /dev/null
+++ b/test/asan/TestCases/speculative_load.cc
@@ -0,0 +1,50 @@
+// Verifies that speculative loads from unions do not happen under asan.
+// RUN: %clangxx_asan -O0 %s -o %t && %run %t 2>&1
+// RUN: %clangxx_asan -O1 %s -o %t && %run %t 2>&1
+// RUN: %clangxx_asan -O2 %s -o %t && %run %t 2>&1
+// RUN: %clangxx_asan -O3 %s -o %t && %run %t 2>&1
+
+#include <sanitizer/asan_interface.h>
+
+struct S {
+ struct _long {
+ void* _pad;
+ const char* _ptr;
+ };
+
+ struct _short {
+ unsigned char _size;
+ char _ch[23];
+ };
+
+ union {
+ _short _s;
+ _long _l;
+ } _data;
+
+ S() {
+ _data._s._size = 0;
+ __asan_poison_memory_region(_data._s._ch, 23);
+ }
+
+ bool is_long() const {
+ return _data._s._size & 1;
+ }
+
+ const char* get_pointer() const {
+ return is_long() ? _data._l._ptr : _data._s._ch;
+ }
+};
+
+
+inline void side_effect(const void *arg) {
+ __asm__ __volatile__("" : : "r" (arg) : "memory");
+}
+
+int main(int argc, char **argv) {
+ S s;
+ side_effect(&s); // optimizer is too smart otherwise
+ const char *ptr = s.get_pointer();
+ side_effect(ptr); // force use ptr
+ return 0;
+}