Fix #2054 Differing behaviours with defer statements for single vs multiple return values caused by naïve ABI optimization

This commit is contained in:
gingerBill
2022-09-17 10:20:04 +01:00
parent 9842019205
commit 98eaf5c6c0

View File

@@ -577,20 +577,13 @@ void lb_begin_procedure_body(lbProcedure *p) {
if (e->token.string != "") {
GB_ASSERT(!is_blank_ident(e->token));
lbAddr res = {};
if (return_ptr_value.value != nullptr) {
lbValue ptr = return_ptr_value;
if (results->variables.count != 1) {
ptr = lb_emit_struct_ep(p, ptr, cast(i32)i);
}
res = lb_addr(ptr);
lb_add_entity(p->module, e, ptr);
lb_add_debug_local_variable(p, ptr.value, e->type, e->token);
} else {
res = lb_add_local(p, e->type, e);
}
// NOTE(bill): Don't even bother trying to optimize this with the return ptr value
// This will violate the defer rules if you do:
// foo :: proc() -> (x, y: T) {
// defer x = ... // defer is executed after the `defer`
// return // the values returned should be zeroed
// }
lbAddr res = lb_add_local(p, e->type, e);
if (e->Variable.param_value.kind != ParameterValue_Invalid) {
lbValue c = lb_handle_param_value(p, e->type, e->Variable.param_value, e->token.pos);
lb_addr_store(p, res, c);