-
Notifications
You must be signed in to change notification settings - Fork 97
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
Handle non returning intrinsics #736
Handle non returning intrinsics #736
Conversation
5d128eb
to
5079c97
Compare
let loc = self.codegen_span_option(span); | ||
debug!("codegen_nonret_intrinsic:\n\tinstance {:?}\n\tspan {:?}", instance, span); | ||
match intrinsic { | ||
"abort" => Stmt::assert_false("reached intrinsic::abort", loc), |
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.
I recommend using GotocCtx::codegen_fatal_error()
here. The Stmt::assert_false
will not abort the program execution path.
@@ -29,6 +29,24 @@ impl<'tcx> GotocCtx<'tcx> { | |||
self.codegen_expr_to_place(p, e) | |||
} | |||
|
|||
/// Handles codegen for non returning intrinsics | |||
/// Non returning intrinsics are not associated with a destination | |||
pub fn codegen_nonret_intrinsic( |
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.
nit: I would rename it to codegen_never_return_intrinsic()
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.
It looks good. We do need to add either an assume(false)
or abort()
call after the assert(false)
though. In gotoc, an assertion failure does not interrupt the execution flow which may cause some odd behavior.
Thanks @celinval ! Renamed and replaced |
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.
Perfect! Thanks
* Handle non returning intrinsics * Newline in comment * Address comments
* Handle non returning intrinsics * Newline in comment * Address comments
* Handle non returning intrinsics * Newline in comment * Address comments
* Handle non returning intrinsics * Newline in comment * Address comments
Description of changes:
Adds a specific function for handling of non returning intrinsics, which currently are
abort
and a special case oftransmute
.Resolved issues:
Resolves #734
Call-outs:
Wrote a function for these special intrinsics but they can also be handled within the
codegen_intrinsic
function. That would require passingp
as an option (i.e., not unwrap before call tocodegen_intrinsic
) and match on it at the beginning ofcodegen_intrinsic
. Let me know if you prefer it that way.Testing:
How is this change tested? Existing regression + new test for transmute.
Is this a refactor change? No.
Checklist
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.