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 %t 2>&1 | FileCheck %s 6 7 int *arr; 8 9 __attribute__((always_inline)) 10 void inlined(int arg) { 11 int x[5]; 12 for (int i = 0; i < arg; i++) x[i] = i; 13 arr = x; 14 } 15 16 int main(int argc, char *argv[]) { 17 inlined(argc); 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.cc:[[@LINE-4]] 23 // CHECK: Address 0x{{.*}} is located in stack of thread T0 at offset 24 // CHECK: [[OFFSET:[^ ]*]] in frame 25 // CHECK: main 26 // CHECK: {{\[}}[[OFFSET]], {{.*}}) 'x.i' 27 } 28