[Mlir-commits] [mlir] [mlir][llvm dialect] Verify element type of nested types (PR #148975)

Tobias Gysi llvmlistbot at llvm.org
Tue Jul 15 23:31:30 PDT 2025


================
@@ -3271,13 +3293,23 @@ LogicalResult LLVM::ConstantOp::verify() {
     }
     if (!isa<VectorType, LLVM::LLVMArrayType>(getType()))
       return emitOpError() << "expected vector or array type";
+
     // The number of elements of the attribute and the type must match.
-    if (auto elementsAttr = dyn_cast<ElementsAttr>(getValue())) {
-      int64_t attrNumElements = elementsAttr.getNumElements();
-      if (getNumElements(getType()) != attrNumElements)
-        return emitOpError()
-               << "type and attribute have a different number of elements: "
-               << getNumElements(getType()) << " vs. " << attrNumElements;
+    int64_t attrNumElements = elementsAttr.getNumElements();
+    if (getNumElements(getType()) != attrNumElements) {
+      return emitOpError()
+             << "type and attribute have a different number of elements: "
+             << getNumElements(getType()) << " vs. " << attrNumElements;
+    }
+
+    Type attrElmType = getElementType(elementsAttr.getType());
+    Type resultElmType = getElementType(getType());
+    if (auto floatType = dyn_cast<FloatType>(attrElmType)) {
+      return verifyFloatSemantics(floatType.getFloatSemantics(), resultElmType);
+    }
----------------
gysit wrote:

```suggestion
    if (auto floatType = dyn_cast<FloatType>(attrElmType)) 
      return verifyFloatSemantics(floatType.getFloatSemantics(), resultElmType);
```
nit: Same as above

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


More information about the Mlir-commits mailing list