@@ -199,7 +199,7 @@ void function_interface_impl::insertFunctionArguments(
199199 // There are 3 things that need to be updated:
200200 // - Function type.
201201 // - Arg attrs.
202- // - Block arguments of entry block.
202+ // - Block arguments of entry block, if not empty .
203203 Block &entry = op->getRegion (0 ).front ();
204204
205205 // Update the argument attributes of the function.
@@ -228,8 +228,11 @@ void function_interface_impl::insertFunctionArguments(
228228
229229 // Update the function type and any entry block arguments.
230230 op.setFunctionTypeAttr (TypeAttr::get (newType));
231- for (unsigned i = 0 , e = argIndices.size (); i < e; ++i)
232- entry.insertArgument (argIndices[i] + i, argTypes[i], argLocs[i]);
231+
232+ // Update the block arguments of the entry block when it is not external.
233+ if (!op.isExternal ())
234+ for (unsigned i = 0 , e = argIndices.size (); i < e; ++i)
235+ entry.insertArgument (argIndices[i] + i, argTypes[i], argLocs[i]);
233236}
234237
235238void function_interface_impl::insertFunctionResults (
@@ -279,7 +282,7 @@ void function_interface_impl::eraseFunctionArguments(
279282 // There are 3 things that need to be updated:
280283 // - Function type.
281284 // - Arg attrs.
282- // - Block arguments of entry block.
285+ // - Block arguments of entry block, if not empty .
283286 Block &entry = op->getRegion (0 ).front ();
284287
285288 // Update the argument attributes of the function.
@@ -294,7 +297,10 @@ void function_interface_impl::eraseFunctionArguments(
294297
295298 // Update the function type and any entry block arguments.
296299 op.setFunctionTypeAttr (TypeAttr::get (newType));
297- entry.eraseArguments (argIndices);
300+
301+ // Update the block arguments of the entry block when it is not external.
302+ if (!op.isExternal ())
303+ entry.eraseArguments (argIndices);
298304}
299305
300306void function_interface_impl::eraseFunctionResults (
0 commit comments