-
Notifications
You must be signed in to change notification settings - Fork 3
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
No basic block terminator in a fall-thru #14
Conversation
7e77f1b
to
e2d27ac
Compare
e2d27ac
to
4dbf8ea
Compare
let terminator = LLVMGetBasicBlockTerminator(prev_bb); | ||
if terminator.is_null() { | ||
LLVMPositionBuilderAtEnd(self.module_cx.llvm_builder.0, prev_bb); | ||
LLVMBuildBr(self.module_cx.llvm_builder.0, bb); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How do we know that LLVMGetPreviousBasicBlock gives a predecessor of bb? Even if this somehow works, this can lead to bug in future.
I think we should keep track of previous basic block in translate_instruction
and pass that information to fix_terminator_in_prev_bb
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, we know that LLVMGetPreviousBasicBlock gives the correct predecessor since it is how we build them in translate_instruction
.
Providing an additional tracking will be just an unnecessary double booking.
@ksolana thx for quick review! |
Thanks @jcivlin |
* 032424-failure-loop: ini * 032424-failure-loop: fix_bb_terminator * 032424-failure-loop: fix in sbc::Bytecode::Label * 032424-failure-loop: add failure-tests * 032424-failure-loop: fix_bb_terminators and fix_terminator_in_prev_bb
Problem description
Stackless code may have basic block terminators removed by Move compiler optimizer (which is semantically ok for the fall-thru), whereas LLVM requires terminators in all basic blocks (even for the fall-thru).
Solution
This patch provides fixing of this problem and adds (restores) the omitted basic block terminator while translating
sbc::Bytecode::Label bytecode.
Example
For this test:
In the generated code the first br was absent and added in this patch: