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