58 lines · cpp
1// Regression test for https://github.com/google/sanitizers/issues/6912 3// RUN: %clangxx_asan -O0 %s -o %t -fstack-protector4// RUN: %run %t 1 2>&1 | FileCheck %s5// RUN: %run %t 2 2>&1 | FileCheck %s6 7#include <stdio.h>8#include <string.h>9#include <stdlib.h>10#ifdef _MSC_VER11# include <malloc.h>12#endif13 14// MSVC provides _alloca instead of alloca.15#if defined(_MSC_VER) && !defined(alloca)16# define alloca _alloca17#endif18 19#if defined(__sun__) && defined(__svr4__)20#include <alloca.h>21#endif22 23 24void f1_alloca() {25 char *dynamic_buffer = (char *)alloca(200);26 fprintf(stderr, "dynamic_buffer = %p\n", dynamic_buffer);27 memset(dynamic_buffer, 'y', 200);28 return;29}30 31static const int kDynamicArraySize = 200;32 33void f1_vla() {34 char dynamic_buffer[kDynamicArraySize];35 fprintf(stderr, "dynamic_buffer = %p\n", dynamic_buffer);36 memset(dynamic_buffer, 'y', kDynamicArraySize);37 return;38}39 40void f2() {41 char buf[1024];42 memset(buf, 'x', 1024);43}44 45int main(int argc, const char *argv[]) {46 if (!strcmp(argv[1], "1")) {47 f1_alloca();48 } else if (!strcmp(argv[1], "2")) {49 f1_vla();50 }51 f2();52 fprintf(stderr, "Done.\n");53 return 0;54}55 56// CHECK-NOT: ERROR: AddressSanitizer57// CHECK: Done.58