[Openmp-commits] [openmp] [OpenMP] Use simple VLA implementation to replace uses of actual VLA (PR #71412)

Daniil Dudkin via Openmp-commits openmp-commits at lists.llvm.org
Mon Nov 6 10:13:19 PST 2023


================
@@ -0,0 +1,39 @@
+/*
+ * kmp_utils.h -- Utilities that used internally
+ */
+
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+#ifndef __KMP_UTILS_H__
+#define __KMP_UTILS_H__
+
+#include <cstddef>
+
+/// A simple pure header implementation of VLA that aims to replace uses of
+/// actual VLA, which can cause compile warning.
+/// Similar to the actual VLA, we don't check boundary (for now), so we will not
+/// store the size. We can always revise it later.
+template <typename T> class SimpleVLA final {
+  T *Data = nullptr;
+
+public:
+  SimpleVLA(std::size_t Size) noexcept : Data(new T[Size]) {}
----------------
unterumarmung wrote:

```suggestion
  explicit SimpleVLA(std::size_t Size) noexcept : Data(new T[Size]) {}
```
I guess, it is not a desired behavior where an integer can implicitly create an array.

https://github.com/llvm/llvm-project/pull/71412


More information about the Openmp-commits mailing list