| 1 | // RUN: %clangxx_asan -O0 -mllvm -asan-instrument-dynamic-allocas %s -o %t |
| 2 | // RUN: not %run %t 2>&1 | FileCheck %s |
| 3 | // |
| 4 | |
| 5 | #include "defines.h" |
| 6 | #include <assert.h> |
| 7 | #include <stdint.h> |
| 8 | #if defined(_MSC_VER) && !defined(__clang__) |
| 9 | # include <malloc.h> |
| 10 | #endif |
| 11 | |
| 12 | struct A { |
| 13 | char a[3]; |
| 14 | int b[3]; |
| 15 | }; |
| 16 | |
| 17 | ATTRIBUTE_NOINLINE void foo(int index, int len) { |
| 18 | #if !defined(_MSC_VER) || defined(__clang__) |
| 19 | volatile struct A str[len] ATTRIBUTE_ALIGNED(32); |
| 20 | #else |
| 21 | volatile struct A *str = (volatile struct A *)_alloca(len * sizeof(struct A)); |
| 22 | #endif |
| 23 | assert(!(reinterpret_cast<uintptr_t>(str) & 31L)); |
| 24 | str[index].a[0] = '1'; // BOOM |
| 25 | // CHECK: ERROR: AddressSanitizer: dynamic-stack-buffer-overflow on address [[ADDR:0x[0-9a-f]+]] |
| 26 | // CHECK: WRITE of size 1 at [[ADDR]] thread T0 |
| 27 | } |
| 28 | |
| 29 | int main(int argc, char **argv) { |
| 30 | foo(index: 10, len: 10); |
| 31 | return 0; |
| 32 | } |
| 33 | |