Don't store nullptrs in mlir::FuncOp::getAll*Attrs' result
authorTres Popp <tpopp@google.com>
Mon, 22 Nov 2021 11:49:00 +0000 (12:49 +0100)
committerTres Popp <tpopp@google.com>
Thu, 25 Nov 2021 14:12:29 +0000 (15:12 +0100)
These methods for results and arguments would create an ArrayRef full
of nullptrs when there were no argument attributes. This is problematic
because this result could not be passed to the FuncOp::build creator
without causing a segfault. Now the list will have empty attributes.

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

mlir/include/mlir/IR/FunctionSupport.h

index d86500f..cc086ab 100644 (file)
@@ -390,7 +390,8 @@ public:
       auto argAttrRange = argAttrs.template getAsRange<DictionaryAttr>();
       result.append(argAttrRange.begin(), argAttrRange.end());
     } else {
-      result.resize(getNumArguments());
+      result.append(getNumArguments(),
+                    DictionaryAttr::get(this->getOperation()->getContext()));
     }
   }
 
@@ -479,7 +480,8 @@ public:
       auto argAttrRange = argAttrs.template getAsRange<DictionaryAttr>();
       result.append(argAttrRange.begin(), argAttrRange.end());
     } else {
-      result.resize(getNumResults());
+      result.append(getNumResults(),
+                    DictionaryAttr::get(this->getOperation()->getContext()));
     }
   }