@@ -398,14 +398,21 @@ std::optional<int64_t> vector::getConstantVscaleMultiplier(Value value) {
398
398
399
399
// / Converts an IntegerAttr to have the specified type if needed.
400
400
// / This handles cases where constant attributes have a different type than the
401
- // / target element type. If the input attribute is not an IntegerAttr or already
402
- // / has the correct type, returns it unchanged .
401
+ // / target element type. Returns null if the attribute is poison/invalid or
402
+ // / conversion fails .
403
403
static Attribute convertIntegerAttr (Attribute attr, Type expectedType) {
404
- if (auto intAttr = mlir::dyn_cast<IntegerAttr>(attr)) {
405
- if (intAttr.getType () != expectedType)
406
- return IntegerAttr::get (expectedType, intAttr.getInt ());
407
- }
408
- return attr;
404
+ // Check for poison attributes before any casting operations
405
+ if (!attr || isa<ub::PoisonAttrInterface>(attr))
406
+ return {}; // Poison or invalid attribute
407
+
408
+ auto intAttr = mlir::dyn_cast<IntegerAttr>(attr);
409
+ if (!intAttr)
410
+ return attr; // Not an IntegerAttr, return unchanged (e.g., FloatAttr)
411
+
412
+ if (intAttr.getType () == expectedType)
413
+ return attr; // Already correct type
414
+
415
+ return IntegerAttr::get (expectedType, intAttr.getInt ());
409
416
}
410
417
411
418
// ===----------------------------------------------------------------------===//
@@ -2478,6 +2485,12 @@ static OpFoldResult foldFromElementsToConstant(FromElementsOp fromElementsOp,
2478
2485
return convertIntegerAttr (attr, destEltType);
2479
2486
});
2480
2487
2488
+ // Check if any attributes are poison/invalid (indicated by null attributes).
2489
+ // Note: convertIntegerAttr returns valid non-integer attributes unchanged,
2490
+ // only returns null for poison/invalid attributes.
2491
+ if (llvm::any_of (convertedElements, [](Attribute attr) { return !attr; }))
2492
+ return {};
2493
+
2481
2494
return DenseElementsAttr::get (destVecType, convertedElements);
2482
2495
}
2483
2496
0 commit comments