1 // Test with "-O2" only to make sure inlining (leading to use-after-scope)
2 // happens. "always_inline" is not enough, as Clang doesn't emit
3 // llvm.lifetime intrinsics at -O0.
4 //
5 // RUN: %clangxx_asan -m64 -O2 -fsanitize=use-after-scope %s -o %t && \
6 // RUN: %t 2>&1 | %symbolize | FileCheck %s
7 // RUN: %clangxx_asan -m32 -O2 -fsanitize=use-after-scope %s -o %t && \
8 // RUN: %t 2>&1 | %symbolize | FileCheck %s
9
10 int *arr;
11
12 __attribute__((always_inline))
inlined(int arg)13 void inlined(int arg) {
14 int x[5];
15 for (int i = 0; i < arg; i++) x[i] = i;
16 arr = x;
17 }
18
main(int argc,char * argv[])19 int main(int argc, char *argv[]) {
20 inlined(argc);
21 return arr[argc - 1]; // BOOM
22 // CHECK: ERROR: AddressSanitizer: stack-use-after-scope
23 // CHECK: READ of size 4 at 0x{{.*}} thread T0
24 // CHECK: #0 0x{{.*}} in {{_?}}main
25 // CHECK: {{.*}}use-after-scope-inlined.cc:[[@LINE-4]]
26 // CHECK: Address 0x{{.*}} is located at offset
27 // CHECK: [[OFFSET:[^ ]*]] in frame <main> of T0{{.*}}:
28 // CHECK: {{\[}}[[OFFSET]], {{.*}}) 'x.i'
29 }
30