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