blob: 4b1d6f02ce1ea38cca8cba348ca2aead4b3bffb8 [file] [log] [blame]
Alexey Samsonov889e3ab2013-06-07 09:38:55 +00001// RUN: %clangxx_asan -O0 -fsanitize=use-after-scope %s -o %t && \
Alexey Samsonovb42b2f52013-06-06 08:30:26 +00002// RUN: %t 2>&1 | %symbolize | FileCheck %s
3//
4// Lifetime for temporaries is not emitted yet.
5// XFAIL: *
6
7#include <stdio.h>
8
9struct IntHolder {
10 explicit IntHolder(int val) : val(val) {
11 printf("IntHolder: %d\n", val);
12 }
13 int val;
14};
15
16const IntHolder *saved;
17
18void save(const IntHolder &holder) {
19 saved = &holder;
20}
21
22int 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}