[llvm] Reland [AMDGPU] Add AMDGPU specific variadic operation MCExprs (PR #84562)

Janek van Oirschot via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 11 09:36:57 PDT 2024


================
@@ -20,7 +20,13 @@ using namespace llvm;
 const AMDGPUVariadicMCExpr *
 AMDGPUVariadicMCExpr::create(VariadicKind Kind, ArrayRef<const MCExpr *> Args,
                              MCContext &Ctx) {
-  return new (Ctx) AMDGPUVariadicMCExpr(Kind, Args);
+  // Storage for the argument's 'const MCExpr*' allocated through MCContext new placement which means that AMDGPUVariadicMCExpr objects and all of its contents will now be allocated through MCContext new placement.
+  //
+  // Will result in an asan failure if allocated on the heap (e.g., through SmallVector's grow).
+  const MCExpr **CtxArgs = new (Ctx) const MCExpr*[Args.size()];
+  for (size_t i = 0; i < Args.size(); ++i)
+    CtxArgs[i] = Args[i];
----------------
JanekvO wrote:

> regular old array

Sorry, I'm not sure I understand for what aspect I'd use the array. I can, however, replace the placement new approach with one that uses Ctx.allocate.

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


More information about the llvm-commits mailing list