Position correct basic block before calling error catcher

While building the main function for tests, we may need to generate
additional blocks while marshalling arugments to the error catcher into
the expected calling convention. This pushes the last block in the main
function down, so that the "entry" block may not be last BB in the
function. Instead, look up the last insertion block before generating
the catcher, and then add a call to the catcher at the end of this last
block.

Closes #2300
This commit is contained in:
ayazhafiz 2021-12-30 20:55:43 -06:00
parent 6a38a2948f
commit 983a9f7e17
2 changed files with 11 additions and 1 deletions

View file

@ -3468,9 +3468,11 @@ fn expose_function_to_host_help_c_abi_gen_test<'a, 'ctx, 'env>(
let arguments_for_call = &arguments_for_call.into_bump_slice();
let call_result = {
let last_block = builder.get_insert_block().unwrap();
let roc_wrapper_function = make_exception_catcher(env, roc_function, return_layout);
builder.position_at_end(entry);
builder.position_at_end(last_block);
call_roc_function(
env,