From bd24a131d3b6f78355bbab5c9d9f94ecde32ad7c Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Thu, 27 Dec 2018 16:38:33 -0800 Subject: [PATCH] Fix an ASAN detected bug introduced by cr/227067644. While MLFunctions always have one block, CFG Functions don't necessarily have one (e.g. when they are being first constructed by the parser). PiperOrigin-RevId: 227075636 --- mlir/include/mlir/IR/Builders.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/mlir/include/mlir/IR/Builders.h b/mlir/include/mlir/IR/Builders.h index 386c99fc719b..2efa21a3dc87 100644 --- a/mlir/include/mlir/IR/Builders.h +++ b/mlir/include/mlir/IR/Builders.h @@ -163,10 +163,13 @@ protected: /// automatically inserted at an insertion point. The builder is copyable. class FuncBuilder : public Builder { public: - /// Create an ML function builder and set the insertion point to the start of + /// Create a function builder and set the insertion point to the start of /// the function. FuncBuilder(Function *func) : Builder(func->getContext()), function(func) { - setInsertionPoint(&func->front(), func->front().begin()); + if (!func->empty()) + setInsertionPoint(&func->front(), func->front().begin()); + else + clearInsertionPoint(); } /// Create a function builder and set insertion point to the given statement,