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 %s -o %t && not %run %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(arg: 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.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]]) |
27 | } |
28 | |