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

A. Jiang via Openmp-commits openmp-commits at lists.llvm.org
Mon Nov 6 18:19:03 PST 2023


================
@@ -0,0 +1,42 @@
+/*
+ * 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() = delete;
+  SimpleVLA(const SimpleVLA &) = delete;
+  SimpleVLA(SimpleVLA &&) = default;
+  SimpleVLA &operator=(const SimpleVLA &) = delete;
+  SimpleVLA &operator=(SimpleVLA &&) = default;
----------------
frederick-vs-ja wrote:

Defaulted move functions are still problematic. Once we move constructs a new `SimpleVLA` from the old one, the old one will hold the data, and double-free will probably happen.

Can we simply reuse `unique_ptr<T[]>` and `make_unique`?

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


More information about the Openmp-commits mailing list