# stage2: fix return pointer result locations · gitcafe/zig

[View on GitCafe](https://git.cafe/gitcafe/zig/commit/7d0de54ad44832589379a4bcbba493db2087bebf)

Repository: [gitcafe/zig](https://git.cafe/gitcafe/zig)

Visibility: public

Requested revision: 7d0de54ad44832589379a4bcbba493db2087bebf

Requested commit: 7d0de54ad44832589379a4bcbba493db2087bebf

Commit: 7d0de54ad44832589379a4bcbba493db2087bebf

Tree: 5efb0a82c4ad399e25f603ba25cc6e36566ca845

Author: Andrew Kelley

Committer: Andrew Kelley

## Message

```
stage2: fix return pointer result locations

 * Introduce `ret_load` ZIR instruction which does return semantics
   based on a corresponding `ret_ptr` instruction. If the return type of
   the function has storage for the return type, it simply returns.
   However if the return type of the function is by-value, it loads the
   return value from the `ret_ptr` allocation and returns that.

 * AstGen: improve `finishThenElseBlock` to not emit break instructions
   after a return instruction in the same block.

 * Sema: `ret_ptr` instruction works correctly in comptime contexts.
   Same with `alloc_mut`.

The test case with a recursive inline function having an implicitly
comptime return value now has a runtime return value because of the fact
that it calls a function in a non-comptime context.

```

## Parents

- [e974d4c4295c4fbdbc239caa2cf2d653f65662f1](https://git.cafe/gitcafe/zig/commit/e974d4c4295c4fbdbc239caa2cf2d653f65662f1?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zig/tree/7d0de54ad44832589379a4bcbba493db2087bebf?format=markdown)
