[gn build] Port 0154dce8d39d
[llvm-project.git] / compiler-rt / test / nsan / alloca.cpp
blob33f7c1364e664280d6cb3b849044768a5b04af28
1 // RUN: %clangxx_nsan -O0 -g %s -o %t
2 // RUN: %run %t 2>&1 | FileCheck %s
4 // RUN: %clangxx_nsan -O3 -g %s -o %t
5 // RUN: %run %t 2>&1 | FileCheck %s
7 #include <cstddef>
9 #include "helpers.h"
11 extern "C" void __nsan_dump_shadow_mem(const char *addr, size_t size_bytes,
12 size_t bytes_per_line, size_t reserved);
14 int main() {
15 int size = 3 * sizeof(float);
16 // Make sure we allocate dynamically: https://godbolt.org/z/T3h998.
17 DoNotOptimize(size);
18 float *array = reinterpret_cast<float *>(__builtin_alloca(size));
19 DoNotOptimize(array);
20 array[0] = 1.0;
21 array[1] = 2.0;
22 // The third float is uninitialized.
23 __nsan_dump_shadow_mem((const char *)array, 3 * sizeof(float), 16, 0);
24 // CHECK: {{.*}} f0 f1 f2 f3 f0 f1 f2 f3 __ __ __ __ (1.00000000000000000000) (2.00000000000000000000)
25 return 0;