@@ -199,8 +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.
203
- Block &entry = op->getRegion (0 ).front ();
202
+ // - Block arguments of entry block, if not empty.
204
203
205
204
// Update the argument attributes of the function.
206
205
ArrayAttr oldArgAttrs = op.getArgAttrsAttr ();
@@ -226,10 +225,15 @@ void function_interface_impl::insertFunctionArguments(
226
225
setAllArgAttrDicts (op, newArgAttrs);
227
226
}
228
227
229
- // Update the function type and any entry block arguments .
228
+ // Update the function type.
230
229
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]);
230
+
231
+ // Update entry block arguments, if not empty.
232
+ if (!op.isExternal ()) {
233
+ Block &entry = op->getRegion (0 ).front ();
234
+ for (unsigned i = 0 , e = argIndices.size (); i < e; ++i)
235
+ entry.insertArgument (argIndices[i] + i, argTypes[i], argLocs[i]);
236
+ }
233
237
}
234
238
235
239
void function_interface_impl::insertFunctionResults (
@@ -279,8 +283,7 @@ void function_interface_impl::eraseFunctionArguments(
279
283
// There are 3 things that need to be updated:
280
284
// - Function type.
281
285
// - Arg attrs.
282
- // - Block arguments of entry block.
283
- Block &entry = op->getRegion (0 ).front ();
286
+ // - Block arguments of entry block, if not empty.
284
287
285
288
// Update the argument attributes of the function.
286
289
if (ArrayAttr argAttrs = op.getArgAttrsAttr ()) {
@@ -292,9 +295,14 @@ void function_interface_impl::eraseFunctionArguments(
292
295
setAllArgAttrDicts (op, newArgAttrs);
293
296
}
294
297
295
- // Update the function type and any entry block arguments .
298
+ // Update the function type.
296
299
op.setFunctionTypeAttr (TypeAttr::get (newType));
297
- entry.eraseArguments (argIndices);
300
+
301
+ // Update entry block arguments, if not empty.
302
+ if (!op.isExternal ()) {
303
+ Block &entry = op->getRegion (0 ).front ();
304
+ entry.eraseArguments (argIndices);
305
+ }
298
306
}
299
307
300
308
void function_interface_impl::eraseFunctionResults (
0 commit comments