Skip to content

Conversation

@BertalanD
Copy link
Contributor

When a block contains a return statement, we should not add another br instruction at its end, as it's already terminated. This was previously achieved by setting the insertion point to null when encountering a ResolvedReturnStmt.

Unfortunately, this "orphan" br is still considered a predecessor of the target basic block (which is shown by preds = <null operand!> in the IR). If using a debug build of LLVM, this triggers a "Uses remain when a value is destroyed!" assertion in ~BasicBlock, as the br is never destroyed.

When a block contains a `return` statement, we should not add another
`br` instruction at its end, as it's already terminated. This was
previously achieved by setting the insertion point to null when
encountering a `ResolvedReturnStmt`.

Unfortunately, this "orphan" `br` is still considered a predecessor of
the target basic block (which is shown by `preds = <null operand!>` in
the IR). If using a debug build of LLVM, this triggers a "Uses remain
when a value is destroyed!" assertion in `~BasicBlock`, as the `br` is
never destroyed.
@isuckatcs
Copy link
Owner

Thank you for catching this! I would have a few suggestions for the implementation though in #6. Please let me know what you think about them.

@isuckatcs isuckatcs closed this Mar 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants