diff --git a/mlir/lib/IR/BuiltinTypes.cpp b/mlir/lib/IR/BuiltinTypes.cpp --- a/mlir/lib/IR/BuiltinTypes.cpp +++ b/mlir/lib/IR/BuiltinTypes.cpp @@ -214,7 +214,10 @@ return num; } -int64_t ShapedType::getRank() const { return getShape().size(); } +int64_t ShapedType::getRank() const { + assert(hasRank() && "cannot query rank of unranked shaped type"); + return getShape().size(); +} bool ShapedType::hasRank() const { return !isa();