Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes https://github.com/sampsyo/bril/issues/342 #343

Merged
merged 5 commits into from
Oct 26, 2024

Conversation

Pat-Lafon
Copy link
Contributor

Unterminated, non-void basic_blocks weren't handled in brillvm. I think this is only ever an issue of dead code(for if this was reachable, then the Bril code would not be well-formed).

The simplest solution may actually be to insert a jump to some arbitrary block instead of trying to craft a well-typed return.

@Pat-Lafon
Copy link
Contributor Author

Seems like brilift also has this issue. The slight wrinkle is that jumps in cranelift take arguments. I've used a trap instead with an arbitrarily chosen trap code... which is maybe a more principled solution anyways.

Copy link
Contributor

@oflatt oflatt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're the best, thanks!

// This block did not have a terminating instruction
// Returning void is ill-typed for this function
// This code should be unreachable in well-formed Bril
// Let's just arbitrarily jump to avoid needing to
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤣

@@ -1294,28 +1294,29 @@ pub fn create_module_from_program<'a>(
}
});

(llvm_func, instrs, block, heap)
(llvm_func, instrs, block, heap, return_type)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could preserve original function here instead of instrs and return_type
That, or do a zip later with the original functions and the llvm ones

@sampsyo
Copy link
Owner

sampsyo commented Oct 26, 2024

Awesome; good thinking here!! And trapping in the generated CLIF seems like a good idea. I'll poke around in the Cranelift docs to see if there's something else obvious to use here, just in case.

@sampsyo sampsyo merged commit 250c1b1 into sampsyo:main Oct 26, 2024
17 checks passed
sampsyo added a commit that referenced this pull request Oct 26, 2024
Pat-Lafon pushed a commit to Pat-Lafon/bril that referenced this pull request Nov 4, 2024
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.

3 participants