Skip to content

Emit traps for unreachable nodes#41465

Merged
JeffBezanson merged 2 commits intomasterfrom
kf/unreachabletrap
Jul 6, 2021
Merged

Emit traps for unreachable nodes#41465
JeffBezanson merged 2 commits intomasterfrom
kf/unreachabletrap

Conversation

@Keno
Copy link
Copy Markdown
Member

@Keno Keno commented Jul 5, 2021

Raw unreachable in LLVM is somewhat dangerous since LLVM will literally
stop emitting code there, so if the unreachable is wrong, execution will
crash into whatever subsequent code exists, causing strange and mysterious
errors and incorrect backtraces that are hard to debug without rr. As a
result, we basically always emit a safety trap call before an unreachable
terminator, which will abort execution at the point where unreachable was
executed and at least provide proper backtraces. However, we neglected
to do this for literal unreachables that came from Julia IR (i.e. ReturnNodes
with undef val field). Fix that to make debugging easier if unreachable
ever gets accidentally executed.

Raw `unreachable` in LLVM is somewhat dangerous since LLVM will literally
stop emitting code there, so if the unreachable is wrong, execution will
crash into whatever subsequent code exists, causing strange and mysterious
errors and incorrect backtraces that are hard to debug without rr. As a
result, we basically always emit a safety trap call before an `unreachable`
terminator, which will abort execution at the point where unreachable was
executed and at least provide proper backtraces. However, we neglected
to do this for literal unreachables that came from Julia IR (i.e. ReturnNodes
with undef val field). Fix that to make debugging easier if unreachable
ever gets accidentally executed.
Co-authored-by: Jameson Nash <vtjnash@gmail.com>
@JeffBezanson JeffBezanson added the compiler:codegen Generation of LLVM IR and native code label Jul 6, 2021
@JeffBezanson JeffBezanson merged commit c73901e into master Jul 6, 2021
@JeffBezanson JeffBezanson deleted the kf/unreachabletrap branch July 6, 2021 21:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

compiler:codegen Generation of LLVM IR and native code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants