[Mlir-commits] [mlir] 73de3df - Add more explicit assert for failures

Jacques Pienaar llvmlistbot at llvm.org
Fri Jan 22 11:45:41 PST 2021


Author: Jacques Pienaar
Date: 2021-01-22T11:45:25-08:00
New Revision: 73de3df1d28523dbd67dd54594480d126e27b559

URL: https://github.com/llvm/llvm-project/commit/73de3df1d28523dbd67dd54594480d126e27b559
DIFF: https://github.com/llvm/llvm-project/commit/73de3df1d28523dbd67dd54594480d126e27b559.diff

LOG: Add more explicit assert for failures

Differential Revision: https://reviews.llvm.org/D95201

Added: 
    

Modified: 
    mlir/lib/IR/BuiltinTypes.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/lib/IR/BuiltinTypes.cpp b/mlir/lib/IR/BuiltinTypes.cpp
index 34283e95b8f5..23553a8483de 100644
--- a/mlir/lib/IR/BuiltinTypes.cpp
+++ b/mlir/lib/IR/BuiltinTypes.cpp
@@ -214,7 +214,10 @@ int64_t ShapedType::getNumElements() const {
   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<UnrankedMemRefType, UnrankedTensorType>();


        


More information about the Mlir-commits mailing list