[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 07:56:48 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:

I was hoping so as well, but when I looked into it `SmallVector` did not have any way to provide an alternate allocator nor does `MCContext` provide the llvm Allocator interface. The `BumpPtrAllocator` used in `MCContext` is also not directly accessible leaving not that many options.

The `AMDGPUVariadicMCExpr::create` function is currently the only place that does the direct creation of the AMDGPUVariadicMCExpr and uses `MCContext` placement new so it seems the most fitting place for this copy code. For now I've replaced the manual copy with `std::copy`.

Do let me know if I'm missing something obvious in terms of allocator behaviour in `SmallVector` or `ArrayRef`.

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


More information about the llvm-commits mailing list