@@ -199,7 +199,7 @@ void function_interface_impl::insertFunctionArguments(
199
199
// There are 3 things that need to be updated:
200
200
// - Function type.
201
201
// - Arg attrs.
202
- // - Block arguments of entry block.
202
+ // - Block arguments of entry block, if not empty .
203
203
Block &entry = op->getRegion (0 ).front ();
204
204
205
205
// Update the argument attributes of the function.
@@ -228,8 +228,11 @@ void function_interface_impl::insertFunctionArguments(
228
228
229
229
// Update the function type and any entry block arguments.
230
230
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]);
233
236
}
234
237
235
238
void function_interface_impl::insertFunctionResults (
@@ -279,7 +282,7 @@ void function_interface_impl::eraseFunctionArguments(
279
282
// There are 3 things that need to be updated:
280
283
// - Function type.
281
284
// - Arg attrs.
282
- // - Block arguments of entry block.
285
+ // - Block arguments of entry block, if not empty .
283
286
Block &entry = op->getRegion (0 ).front ();
284
287
285
288
// Update the argument attributes of the function.
@@ -294,7 +297,10 @@ void function_interface_impl::eraseFunctionArguments(
294
297
295
298
// Update the function type and any entry block arguments.
296
299
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);
298
304
}
299
305
300
306
void function_interface_impl::eraseFunctionResults (
0 commit comments