summaryrefslogtreecommitdiff
path: root/test/asan
diff options
context:
space:
mode:
authorVitaly Buka <vitalybuka@google.com>2017-08-29 21:23:44 +0000
committerVitaly Buka <vitalybuka@google.com>2017-08-29 21:23:44 +0000
commit25500b158196752cb12a88207ba1fe5c9a86f5b1 (patch)
tree1e298f2bce1667ff64dae0ff73a99ced959fea07 /test/asan
parent730138a7ef0556eb25df17377f6d8b6824818c16 (diff)
[asan] Add use-after-scope test which fails because of bug in clang
Reviewers: kcc, eugenis Subscribers: llvm-commits, kubamracek Differential Revision: https://reviews.llvm.org/D37242 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@312039 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/asan')
-rw-r--r--test/asan/TestCases/use-after-scope-conversion.cc50
1 files changed, 50 insertions, 0 deletions
diff --git a/test/asan/TestCases/use-after-scope-conversion.cc b/test/asan/TestCases/use-after-scope-conversion.cc
new file mode 100644
index 000000000..99b845d07
--- /dev/null
+++ b/test/asan/TestCases/use-after-scope-conversion.cc
@@ -0,0 +1,50 @@
+// RUN: %clangxx_asan -O0 -fsanitize-address-use-after-scope %s -o %t
+
+// RUN: not %run %t 'A' 2>&1 | FileCheck %s
+// RUN: not %run %t 'B' 2>&1 | FileCheck %s
+
+// Missing lifetime markers in test_a
+// https://bugs.llvm.org/show_bug.cgi?id=34353
+// XFAIL: *
+
+struct B {
+ B() : p('B') {}
+ char p;
+};
+
+struct C {
+ const char *p;
+ explicit C(const char *c) : p(c) {}
+ C(const B &b) : p(&b.p) {} // NOLINT
+};
+
+struct A {
+ char p;
+ explicit A() : p('C') {}
+ const operator C() const { return C(&p); }
+};
+
+volatile char r;
+void test_a() {
+ C s = A();
+ r = *s.p;
+}
+
+void test_b() {
+ C s = B();
+ r = *s.p;
+}
+
+int main(int argc, char **argv) {
+ switch (argv[1][0]) {
+ case 'A':
+ test_a();
+ return 0;
+ case 'B':
+ test_b();
+ return 0;
+ }
+ return 1;
+}
+
+// CHECK: ERROR: AddressSanitizer: stack-use-after-scope