1673dc3d4SNico Weber // RUN: %clangxx_asan -O0 -fsanitize-address-use-after-scope %s -o %t
2673dc3d4SNico Weber 
3673dc3d4SNico Weber // RUN: not %run %t 'A' 2>&1 | FileCheck %s
4673dc3d4SNico Weber // RUN: not %run %t 'B' 2>&1 | FileCheck %s
5673dc3d4SNico Weber 
6673dc3d4SNico Weber // Missing lifetime markers in test_a
7673dc3d4SNico Weber // https://bugs.llvm.org/show_bug.cgi?id=34353
8673dc3d4SNico Weber // XFAIL: *
9673dc3d4SNico Weber 
10673dc3d4SNico Weber struct B {
BB11673dc3d4SNico Weber   B() : p('B') {}
12673dc3d4SNico Weber   char p;
13673dc3d4SNico Weber };
14673dc3d4SNico Weber 
15673dc3d4SNico Weber struct C {
16673dc3d4SNico Weber   const char *p;
CC17673dc3d4SNico Weber   explicit C(const char *c) : p(c) {}
CC18*c0fa6322SVitaly Buka   explicit C(const B &b) : p(&b.p) {}
19673dc3d4SNico Weber };
20673dc3d4SNico Weber 
21673dc3d4SNico Weber struct A {
22673dc3d4SNico Weber   char p;
AA2348eb4a27SVitaly Buka   A() : p('C') {}
operator CA24673dc3d4SNico Weber   const operator C() const { return C(&p); }
25673dc3d4SNico Weber };
26673dc3d4SNico Weber 
27673dc3d4SNico Weber volatile char r;
test_a()28673dc3d4SNico Weber void test_a() {
29673dc3d4SNico Weber   C s = A();
30673dc3d4SNico Weber   r = *s.p;
31673dc3d4SNico Weber }
32673dc3d4SNico Weber 
test_b()33673dc3d4SNico Weber void test_b() {
34673dc3d4SNico Weber   C s = B();
35673dc3d4SNico Weber   r = *s.p;
36673dc3d4SNico Weber }
37673dc3d4SNico Weber 
main(int argc,char ** argv)38673dc3d4SNico Weber int main(int argc, char **argv) {
39673dc3d4SNico Weber   switch (argv[1][0]) {
40673dc3d4SNico Weber   case 'A':
41673dc3d4SNico Weber     test_a();
42673dc3d4SNico Weber     return 0;
43673dc3d4SNico Weber   case 'B':
44673dc3d4SNico Weber     test_b();
45673dc3d4SNico Weber     return 0;
46673dc3d4SNico Weber   }
47673dc3d4SNico Weber   return 1;
48673dc3d4SNico Weber }
49673dc3d4SNico Weber 
50673dc3d4SNico Weber // CHECK: ERROR: AddressSanitizer: stack-use-after-scope
51