[Mlir-commits] [mlir] [mlir][vector] Fix crash in vector.from_elements folding with poison values (PR #158528)

Yang Bai llvmlistbot at llvm.org
Tue Sep 16 04:01:24 PDT 2025


================
@@ -2472,10 +2473,12 @@ static OpFoldResult foldFromElementsToConstant(FromElementsOp fromElementsOp,
   if (!destEltType.isIntOrIndexOrFloat() && !isa<ComplexType>(destEltType))
     return {};
 
-  // Constant attributes might have a different type than the return type.
-  // Convert them before creating the dense elements attribute.
-  auto convertedElements = llvm::map_to_vector(elements, [&](Attribute attr) {
-    return convertIntegerAttr(attr, destEltType);
+  // Convert integer attributes to the target type if needed, leave others unchanged.
+  auto convertedElements = llvm::map_to_vector(elements, [&](Attribute attr) -> Attribute {
+    if (auto intAttr = dyn_cast<IntegerAttr>(attr)) {
+      return convertIntegerAttr(intAttr, destEltType);
+    }
+    return attr; // Non-integer attributes (FloatAttr, etc.) returned unchanged
----------------
yangtetris wrote:

That makes sense. As described in https://github.com/llvm/llvm-project/pull/147691, such type mismatches can also occur with float attributes. This part has been missing.
IMHO, we can:
1. Rename `convertIntegerAttr` to `convertNumericAttr`, and add an assertion to ensure the input attribute is either an integer or float attribute.
2. Or, add a new helper function `convertFloatAttr`.

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


More information about the Mlir-commits mailing list