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

source code of compiler-rt/test/nsan/alloca.cpp