Alexey Samsonov | 889e3ab | 2013-06-07 09:38:55 +0000 | [diff] [blame^] | 1 | // RUN: %clangxx_asan -O0 -fsanitize=use-after-scope %s -o %t && \ |
Alexey Samsonov | b42b2f5 | 2013-06-06 08:30:26 +0000 | [diff] [blame] | 2 | // RUN: %t 2>&1 | %symbolize | FileCheck %s |
| 3 | // |
| 4 | // Lifetime for temporaries is not emitted yet. |
| 5 | // XFAIL: * |
| 6 | |
| 7 | #include <stdio.h> |
| 8 | |
| 9 | struct IntHolder { |
| 10 | explicit IntHolder(int val) : val(val) { |
| 11 | printf("IntHolder: %d\n", val); |
| 12 | } |
| 13 | int val; |
| 14 | }; |
| 15 | |
| 16 | const IntHolder *saved; |
| 17 | |
| 18 | void save(const IntHolder &holder) { |
| 19 | saved = &holder; |
| 20 | } |
| 21 | |
| 22 | int main(int argc, char *argv[]) { |
| 23 | save(IntHolder(10)); |
| 24 | int x = saved->val; // BOOM |
| 25 | // CHECK: ERROR: AddressSanitizer: stack-use-after-scope |
| 26 | // CHECK: #0 0x{{.*}} in {{_?}}main {{.*}}use-after-scope-temp.cc:[[@LINE-2]] |
| 27 | printf("saved value: %d\n", x); |
| 28 | return 0; |
| 29 | } |