We currently, incorrectly, assume that a range always has at least
one element when building a contiguous range. This commit adds
a proper empty check to avoid crashing.
Differential Revision: https://reviews.llvm.org/D110457
template <typename T>
::mlir::FailureOr<::mlir::detail::ElementsAttrIndexer> buildValueResult(
/*isContiguous*/std::true_type) const {
+ if ($_attr.empty()) {
+ return ::mlir::detail::ElementsAttrIndexer::contiguous<T>(
+ /*isSplat=*/false, nullptr);
+ }
+
auto valueIt = $_attr.value_begin_impl(OverloadToken<T>());
return ::mlir::detail::ElementsAttrIndexer::contiguous(
$_attr.isSplat(), &*valueIt);
// expected-error@below {{Test iterating `APInt`: unable to iterate type}}
// expected-error@below {{Test iterating `IntegerAttr`: unable to iterate type}}
std.constant opaque<"_", "0xDEADBEEF"> : tensor<5xi64>
+
+// Check that we don't crash on empty element attributes.
+// expected-error@below {{Test iterating `uint64_t`: }}
+// expected-error@below {{Test iterating `APInt`: }}
+// expected-error@below {{Test iterating `IntegerAttr`: }}
+std.constant dense<> : tensor<0xi64>