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.
5 // RUN: %clangxx_asan -O2 %s -o %t && not %run %t 2>&1 | FileCheck %s
9 __attribute__((always_inline
))
10 void inlined(int arg
) {
12 for (int i
= 0; i
< arg
; i
++) x
[i
] = i
;
16 int main(int argc
, char *argv
[]) {
18 return arr
[argc
- 1]; // BOOM
19 // CHECK: ERROR: AddressSanitizer: stack-use-after-scope
20 // CHECK: READ of size 4 at 0x{{.*}} thread T0
21 // CHECK: #0 0x{{.*}} in main
22 // CHECK: {{.*}}use-after-scope-inlined.cpp:[[@LINE-4]]
23 // CHECK: Address 0x{{.*}} is located in stack of thread T0 at offset [[OFFSET:[^ ]*]] in frame
24 // CHECK: {{.*}} in main
25 // CHECK: This frame has
26 // CHECK: {{\[}}[[OFFSET]], {{.*}}) 'x.i' (line [[@LINE-15]])