mirror of
https://github.com/intel/llvm.git
synced 2026-01-24 08:30:34 +08:00
[mlir] Improve error handling for dense attribute parsing in complex types (#133220)
- For splat dense attributes, the number of parsed elements must be 2. - For non-splat dense attributes, the number of parsed elements must be twice the number of elements in the type. Fixes #132859.
This commit is contained in:
@@ -566,6 +566,19 @@ DenseElementsAttr TensorLiteralParser::getAttr(SMLoc loc, ShapedType type) {
|
||||
if (ComplexType complexTy = dyn_cast<ComplexType>(eltType)) {
|
||||
eltType = complexTy.getElementType();
|
||||
isComplex = true;
|
||||
// Complex types have 2 elements.
|
||||
if (shape.empty() && storage.size() != 2) {
|
||||
p.emitError(loc) << "parsed " << storage.size() << " elements, but type ("
|
||||
<< complexTy << ") expected 2 elements";
|
||||
return nullptr;
|
||||
}
|
||||
if (!shape.empty() &&
|
||||
storage.size() != static_cast<size_t>(type.getNumElements()) * 2) {
|
||||
p.emitError(loc) << "parsed " << storage.size() << " elements, but type ("
|
||||
<< type << ") expected " << type.getNumElements() * 2
|
||||
<< " elements";
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
// Handle integer and index types.
|
||||
|
||||
@@ -63,6 +63,21 @@ func.func @elementsattr_toolarge1() -> () {
|
||||
|
||||
// -----
|
||||
|
||||
// expected-error@+1 {{parsed 1 elements, but type ('complex<i64>') expected 2 elements}}
|
||||
#attr = dense<0> : tensor<2xcomplex<i64>>
|
||||
|
||||
// -----
|
||||
|
||||
// expected-error@+1 {{parsed 2 elements, but type ('tensor<2xcomplex<i64>>') expected 4 elements}}
|
||||
#attr = dense<[0, 1]> : tensor<2xcomplex<i64>>
|
||||
|
||||
// -----
|
||||
|
||||
// expected-error@+1 {{parsed 3 elements, but type ('tensor<2xcomplex<i64>>') expected 4 elements}}
|
||||
#attr = dense<[0, (0, 1)]> : tensor<2xcomplex<i64>>
|
||||
|
||||
// -----
|
||||
|
||||
func.func @elementsattr_toolarge2() -> () {
|
||||
"foo"(){bar = dense<[-777]> : tensor<1xi8>} : () -> () // expected-error {{integer constant out of range}}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user