brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.0 KiB · fdb6b98 Raw
32 lines · cpp
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 emit3// llvm.lifetime intrinsics at -O0.4//5// RUN: %clangxx_asan -O2 %s -o %t && not %run %t 2>&1 | FileCheck %s6 7// MSVC marks this as xfail because it doesn't generate the metadata to display the "x.i" offset.8// XFAIL: msvc9#include "defines.h"10 11int *arr;12 13ATTRIBUTE_ALWAYS_INLINE14void inlined(int arg) {15  int x[5];16  for (int i = 0; i < arg; i++) x[i] = i;17  arr = x;18}19 20int main(int argc, char *argv[]) {21  inlined(argc);22  return arr[argc - 1];  // BOOM23  // CHECK: ERROR: AddressSanitizer: stack-use-after-scope24  // CHECK: READ of size 4 at 0x{{.*}} thread T025  // CHECK:   #0 0x{{.*}} in main26  // CHECK:      {{.*}}use-after-scope-inlined.cpp:[[@LINE-4]]27  // CHECK: Address 0x{{.*}} is located in stack of thread T0 at offset [[OFFSET:[^ ]*]] in frame28  // CHECK:      {{.*}} in main29  // CHECK:   This frame has30  // CHECK:     {{\[}}[[OFFSET]], {{.*}}) 'x' (line [[@LINE-15]])31}32