]> git.proxmox.com Git - rustc.git/blame - src/compiler-rt/test/asan/TestCases/use-after-scope-inlined.cc
New upstream version 1.12.0+dfsg1
[rustc.git] / src / compiler-rt / test / asan / TestCases / use-after-scope-inlined.cc
CommitLineData
1a4d82fc
JJ
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//
5bcae85e
SL
5// RUN: %clangxx_asan -O2 -fsanitize-address-use-after-scope %s -o %t && \
6// RUN: not %run %t 2>&1 | FileCheck %s
1a4d82fc
JJ
7
8int *arr;
9
10__attribute__((always_inline))
11void inlined(int arg) {
12 int x[5];
13 for (int i = 0; i < arg; i++) x[i] = i;
14 arr = x;
15}
16
17int main(int argc, char *argv[]) {
18 inlined(argc);
19 return arr[argc - 1]; // BOOM
20 // CHECK: ERROR: AddressSanitizer: stack-use-after-scope
21 // CHECK: READ of size 4 at 0x{{.*}} thread T0
22 // CHECK: #0 0x{{.*}} in main
23 // CHECK: {{.*}}use-after-scope-inlined.cc:[[@LINE-4]]
24 // CHECK: Address 0x{{.*}} is located in stack of thread T0 at offset
25 // CHECK: [[OFFSET:[^ ]*]] in frame
26 // CHECK: main
27 // CHECK: {{\[}}[[OFFSET]], {{.*}}) 'x.i'
28}