1 | // RUN: %clangxx_asan -O0 %s -o %t |
2 | |
3 | // RUN: not %run %t 'A' 2>&1 | FileCheck %s |
4 | // RUN: not %run %t 'B' 2>&1 | FileCheck %s |
5 | |
6 | // Missing lifetime markers in test_a |
7 | // https://bugs.llvm.org/show_bug.cgi?id=34353 |
8 | // XFAIL: * |
9 | |
10 | struct B { |
11 | B() : p('B') {} |
12 | char p; |
13 | }; |
14 | |
15 | struct C { |
16 | const char *p; |
17 | explicit C(const char *c) : p(c) {} |
18 | explicit C(const B &b) : p(&b.p) {} |
19 | }; |
20 | |
21 | struct A { |
22 | char p; |
23 | A() : p('C') {} |
24 | const operator C() const { return C(&p); } |
25 | }; |
26 | |
27 | volatile char r; |
28 | void test_a() { |
29 | C s = A(); |
30 | r = *s.p; |
31 | } |
32 | |
33 | void test_b() { |
34 | C s = B(); |
35 | r = *s.p; |
36 | } |
37 | |
38 | int main(int argc, char **argv) { |
39 | switch (argv[1][0]) { |
40 | case 'A': |
41 | test_a(); |
42 | return 0; |
43 | case 'B': |
44 | test_b(); |
45 | return 0; |
46 | } |
47 | return 1; |
48 | } |
49 | |
50 | // CHECK: ERROR: AddressSanitizer: stack-use-after-scope |
51 | |