]> git.proxmox.com Git - rustc.git/blob - src/libcompiler_builtins/compiler-rt/test/asan/TestCases/alloca_detect_custom_size_.cc
New upstream version 1.20.0+dfsg1
[rustc.git] / src / libcompiler_builtins / compiler-rt / test / asan / TestCases / alloca_detect_custom_size_.cc
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 <assert.h>
6
7 struct A {
8 char a[3];
9 int b[3];
10 };
11
12 __attribute__((noinline)) void foo(int index, int len) {
13 volatile struct A str[len] __attribute__((aligned(32)));
14 assert(!(reinterpret_cast<long>(str) & 31L));
15 str[index].a[0] = '1'; // BOOM
16 // CHECK: ERROR: AddressSanitizer: dynamic-stack-buffer-overflow on address [[ADDR:0x[0-9a-f]+]]
17 // CHECK: WRITE of size 1 at [[ADDR]] thread T0
18 }
19
20 int main(int argc, char **argv) {
21 foo(10, 10);
22 return 0;
23 }