diff --git a/mlir/lib/Parser/TypeParser.cpp b/mlir/lib/Parser/TypeParser.cpp --- a/mlir/lib/Parser/TypeParser.cpp +++ b/mlir/lib/Parser/TypeParser.cpp @@ -504,8 +504,8 @@ consumeToken(); } else { // Make sure this integer value is in bound and valid. - auto dimension = getToken().getUnsignedIntegerValue(); - if (!dimension.hasValue()) + Optional dimension = getToken().getUInt64IntegerValue(); + if (!dimension || *dimension > std::numeric_limits::max()) return emitError("invalid dimension"); dimensions.push_back((int64_t)dimension.getValue()); consumeToken(Token::integer); diff --git a/mlir/test/IR/invalid.mlir b/mlir/test/IR/invalid.mlir --- a/mlir/test/IR/invalid.mlir +++ b/mlir/test/IR/invalid.mlir @@ -20,6 +20,11 @@ // ----- +// expected-error@+1 {{invalid dimension}} +#large_dim = tensor<9223372036854775808xf32> + +// ----- + func @illegalmemrefelementtype(memref>) -> () // expected-error {{invalid memref element type}} // ----- diff --git a/mlir/test/IR/parser.mlir b/mlir/test/IR/parser.mlir --- a/mlir/test/IR/parser.mlir +++ b/mlir/test/IR/parser.mlir @@ -77,6 +77,9 @@ // CHECK: func private @tensor_encoding(tensor<16x32xf64, "sparse">) func private @tensor_encoding(tensor<16x32xf64, "sparse">) +// CHECK: func private @large_shape_dimension(tensor<9223372036854775807xf32>) +func private @large_shape_dimension(tensor<9223372036854775807xf32>) + // CHECK: func private @functions((memref<1x?x4x?x?xi32, #map0>, memref<8xi8>) -> (), () -> ()) func private @functions((memref<1x?x4x?x?xi32, #map0, 0>, memref<8xi8, #map1, 0>) -> (), ()->())