[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:20 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:

Also, I'd suggest to explicitly define copy/move constructors and the default one.
For example,
```cpp
  SimpleVLA() = delete;
  SimpleVLA(const SimpleVLA&) = delete;
  SimpleVLA(SimpleVLA&&) = default;
  SimpleVLA& operator=(const SimpleVLA&) = delete;
  SimpleVLA& operator=(SimpleVLA&&) = default;
```

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


More information about the Openmp-commits mailing list