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 | // MSVC marks this as xfail because it doesn't generate the metadata to display the "x.i" offset. |
8 | // XFAIL: msvc |
9 | #include "defines.h" |
10 | |
11 | int *arr; |
12 | |
13 | ATTRIBUTE_ALWAYS_INLINE |
14 | void inlined(int arg) { |
15 | int x[5]; |
16 | for (int i = 0; i < arg; i++) x[i] = i; |
17 | arr = x; |
18 | } |
19 | |
20 | int main(int argc, char *argv[]) { |
21 | inlined(arg: argc); |
22 | return arr[argc - 1]; // BOOM |
23 | // CHECK: ERROR: AddressSanitizer: stack-use-after-scope |
24 | // CHECK: READ of size 4 at 0x{{.*}} thread T0 |
25 | // CHECK: #0 0x{{.*}} in main |
26 | // CHECK: {{.*}}use-after-scope-inlined.cpp:[[@LINE-4]] |
27 | // CHECK: Address 0x{{.*}} is located in stack of thread T0 at offset [[OFFSET:[^ ]*]] in frame |
28 | // CHECK: {{.*}} in main |
29 | // CHECK: This frame has |
30 | // CHECK: {{\[}}[[OFFSET]], {{.*}}) 'x' (line [[@LINE-15]]) |
31 | } |
32 |