brintos

brintos / llvm-project-archived public Read only

0
0
Text · 622 B · d4cf951 Raw
26 lines · cpp
1// RUN: %clangxx_asan -O0 -mllvm -asan-instrument-dynamic-allocas %s -o %t2// RUN: not %run %t 2>&1 | FileCheck %s3//4// REQUIRES: stable-runtime5 6// MSVC doesn't support VLAs7// UNSUPPORTED: msvc8 9#include <assert.h>10#include <stdint.h>11 12void foo(int index, int len) {13  for (int i = 1; i < len; ++i) {14    char array[len];15    assert(!(reinterpret_cast<uintptr_t>(array) & 31L));16    array[index + i] = 0;17// CHECK: ERROR: AddressSanitizer: dynamic-stack-buffer-overflow on address [[ADDR:0x[0-9a-f]+]]18// CHECK: WRITE of size 1 at [[ADDR]] thread T019  }20}21 22int main(int argc, char **argv) {23  foo(9, 21);24  return 0;25}26