[Openmp-commits] [openmp] [Libomptarget][NFC] Remove use of VLA in the AMDGPU plugin (PR #69761)
Joseph Huber via Openmp-commits
openmp-commits at lists.llvm.org
Fri Oct 20 12:43:36 PDT 2023
https://github.com/jhuber6 created https://github.com/llvm/llvm-project/pull/69761
Summary:
We should not rely on a VLA in C++ for the handling of this string. The
size is a true runtime value so we cannot rely on constexpr handling. We
simply use a small vector, whose default size is most likely large
enough to handle whatever size gets output within the stack, but is safe
in cases where it is not.
>From 9b9d5c6aa3b32b933d7dd03d57ca0f2777c7d398 Mon Sep 17 00:00:00 2001
From: Joseph Huber <jhuber6 at vols.utk.edu>
Date: Fri, 20 Oct 2023 14:42:10 -0500
Subject: [PATCH] [Libomptarget][NFC] Remove use of VLA in the AMDGPU plugin
Summary:
We should not rely on a VLA in C++ for the handling of this string. The
size is a true runtime value so we cannot rely on constexpr handling. We
simply use a small vector, whose default size is most likely large
enough to handle whatever size gets output within the stack, but is safe
in cases where it is not.
---
.../libomptarget/plugins-nextgen/amdgpu/src/rtl.cpp | 11 +++++------
1 file changed, 5 insertions(+), 6 deletions(-)
diff --git a/openmp/libomptarget/plugins-nextgen/amdgpu/src/rtl.cpp b/openmp/libomptarget/plugins-nextgen/amdgpu/src/rtl.cpp
index 66a25e29d016276..626ea827cc95ab2 100644
--- a/openmp/libomptarget/plugins-nextgen/amdgpu/src/rtl.cpp
+++ b/openmp/libomptarget/plugins-nextgen/amdgpu/src/rtl.cpp
@@ -1568,7 +1568,7 @@ struct AMDGPUStreamManagerTy final
hsa_agent_t Agent;
/// The maximum number of queues.
- int MaxNumQueues;
+ uint32_t MaxNumQueues;
/// The size of created queues.
int QueueSize;
@@ -2869,15 +2869,14 @@ struct AMDGPUPluginTy final : public GenericPluginTy {
if (Status != HSA_STATUS_SUCCESS)
return Status;
- // TODO: This is not allowed by the standard.
- char ISAName[Length];
- Status = hsa_isa_get_info_alt(ISA, HSA_ISA_INFO_NAME, ISAName);
+ llvm::SmallVector<char> ISAName(Length);
+ Status = hsa_isa_get_info_alt(ISA, HSA_ISA_INFO_NAME, ISAName.begin());
if (Status != HSA_STATUS_SUCCESS)
return Status;
- llvm::StringRef TripleTarget(ISAName);
+ llvm::StringRef TripleTarget(ISAName.begin(), Length);
if (TripleTarget.consume_front("amdgcn-amd-amdhsa"))
- Target = TripleTarget.ltrim('-').str();
+ Target = TripleTarget.ltrim('-').rtrim('\0').str();
return HSA_STATUS_SUCCESS;
});
if (Err)
More information about the Openmp-commits
mailing list