[OptTable] Fix typo VALUE => VALUES (NFCI) (#121523)
[llvm-project.git] / compiler-rt / test / asan / TestCases / alloca_constant_size.cpp
blob8910ea9f8d8e23a44d48cac3dbb139bfba2eea6b
1 // Regression test for https://github.com/google/sanitizers/issues/691
3 // RUN: %clangxx_asan -O0 %s -o %t -fstack-protector
4 // RUN: %run %t 1 2>&1 | FileCheck %s
5 // RUN: %run %t 2 2>&1 | FileCheck %s
7 #include <stdio.h>
8 #include <string.h>
9 #include <stdlib.h>
11 // MSVC provides _alloca instead of alloca.
12 #if defined(_MSC_VER) && !defined(alloca)
13 # define alloca _alloca
14 #endif
16 #if defined(__sun__) && defined(__svr4__)
17 #include <alloca.h>
18 #endif
21 void f1_alloca() {
22 char *dynamic_buffer = (char *)alloca(200);
23 fprintf(stderr, "dynamic_buffer = %p\n", dynamic_buffer);
24 memset(dynamic_buffer, 'y', 200);
25 return;
28 static const int kDynamicArraySize = 200;
30 void f1_vla() {
31 char dynamic_buffer[kDynamicArraySize];
32 fprintf(stderr, "dynamic_buffer = %p\n", dynamic_buffer);
33 memset(dynamic_buffer, 'y', kDynamicArraySize);
34 return;
37 void f2() {
38 char buf[1024];
39 memset(buf, 'x', 1024);
42 int main(int argc, const char *argv[]) {
43 if (!strcmp(argv[1], "1")) {
44 f1_alloca();
45 } else if (!strcmp(argv[1], "2")) {
46 f1_vla();
48 f2();
49 fprintf(stderr, "Done.\n");
50 return 0;
53 // CHECK-NOT: ERROR: AddressSanitizer
54 // CHECK: Done.