1 // RUN: %clangxx_asan -O1 -fsanitize-address-use-after-scope %s -o %t && \ 2 // RUN: not %run %t 2>&1 | FileCheck %s 3 // 4 // Not expected to work yet with HWAsan. 5 // XFAIL: * 6 7 volatile int *p; 8 9 int main() { 10 // Variable goes in and out of scope. 11 for (int i = 0; i < 3; ++i) { 12 int x[3] = {i, i, i}; 13 p = x + i; 14 } 15 return *p; // BOOM 16 // CHECK: ERROR: AddressSanitizer: stack-use-after-scope 17 // CHECK: #0 0x{{.*}} in main {{.*}}use-after-scope-loop-bug.cpp:[[@LINE-2]] 18 // CHECK: Address 0x{{.*}} is located in stack of thread T{{.*}} at offset [[OFFSET:[^ ]+]] in frame 19 // {{\[}}[[OFFSET]], {{[0-9]+}}) 'x' 20 } 21