[Mlir-commits] [mlir] [mlir][IR] Add `Builder::getArrayAttr` overload for concrete attributes (PR #170870)

Mehdi Amini llvmlistbot at llvm.org
Fri Dec 5 08:18:56 PST 2025


================
@@ -112,6 +112,15 @@ class Builder {
   StringAttr getStringAttr(const Twine &bytes);
   ArrayAttr getArrayAttr(ArrayRef<Attribute> value);
 
+  // Convenience method for containers of specific attribute types. E.g., this
+  // overload will match SmallVector<IntegerAttr>.
+  template <typename ContainerTy>
+  ArrayAttr getArrayAttr(const ContainerTy &value) {
+    auto ref = ArrayRef(value);
+    return getArrayAttr(ArrayRef<Attribute>(
+        static_cast<const Attribute *>(ref.data()), ref.size()));
----------------
joker-eph wrote:

This isn't safe in general in C++ to cast an array of Derived to an array of Base objects.
I'm not sure if we are in a special case with our attribute hierarchy but that seems scary actually.

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


More information about the Mlir-commits mailing list