[clang] [mlir] [CIR] Implement 'allocsize' function/call attribute lowering (PR #179342)
Tobias Gysi via cfe-commits
cfe-commits at lists.llvm.org
Mon Feb 2 23:47:55 PST 2026
================
@@ -2725,6 +2726,23 @@ static void convertNoBuiltinAttrs(MLIRContext *ctx,
target.setNobuiltinsAttr(ArrayAttr::get(ctx, nbAttrs.getArrayRef()));
}
+template <typename OpTy>
+static void convertAllocsizeAttr(MLIRContext *ctx,
+ const llvm::AttributeSet &attrs, OpTy target) {
+ llvm::Attribute attr = attrs.getAttribute(llvm::Attribute::AllocSize);
+ if (!attr.isValid())
+ return;
+
+ auto [elemSize, numElems] = attr.getAllocSizeArgs();
+ if (numElems)
+ target.setAllocsizeAttr(
+ DenseI32ArrayAttr::get(ctx, {static_cast<int32_t>(elemSize),
+ static_cast<int32_t>(*numElems)}));
+ else
+ target.setAllocsizeAttr(
+ DenseI32ArrayAttr::get(ctx, {static_cast<int32_t>(elemSize)}));
----------------
gysit wrote:
```suggestion
if (numElems) {
target.setAllocsizeAttr(
DenseI32ArrayAttr::get(ctx, {static_cast<int32_t>(elemSize),
static_cast<int32_t>(*numElems)}));
} else {
target.setAllocsizeAttr(
DenseI32ArrayAttr::get(ctx, {static_cast<int32_t>(elemSize)}));
}
```
ultra nit: I would go with braces here.
https://github.com/llvm/llvm-project/pull/179342
More information about the cfe-commits
mailing list