-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Use call
instead of invoke
for functions that cannot unwind
#70467
Conversation
There are some LLVM intrinsics that do support invokes, you can find the list at https://github.com/llvm/llvm-project/blob/30a8b77080b98ffdd1837d2ea2e74f91e40cc867/llvm/lib/IR/Verifier.cpp#L4164-L4175. Apart from maybe the wasm one, probably nothing that's relevant to Rust. As a side-note, LLVM intrinsics should always use the "unadjusted" ABI, something that is not happening right now. |
I think this PR is branded as fixing a bug, but it's changing a lot about how @nikic I think those intrinsics (if ever used directly from a library, which we should've never allowed, but that's another discussion) should be marked explicitly with |
This comment has been minimized.
This comment has been minimized.
c0d2691
to
5461dff
Compare
I agree. I wouldn't want to maintain a list of unwinding intrinsics in rustc and using |
☔ The latest upstream changes (presumably #70536) made this pull request unmergeable. Please resolve the merge conflicts. |
src/librustc/ty/layout.rs
Outdated
mk_arg_type: impl Fn(Ty<'tcx>, Option<usize>) -> ArgAbi<'tcx, Ty<'tcx>>, | ||
) -> Self; | ||
fn adjust_for_abi(&mut self, cx: &C, abi: SpecAbi); | ||
} | ||
|
||
fn can_unwind( |
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.
If this logic now lives in librustc
, that might help with #65303.
…ddyb Add `can_unwind` field to `FnAbi` This is a pure refactoring with no behavior changes. Extracted out of rust-lang#70467 r? @eddyb
…ddyb Add `can_unwind` field to `FnAbi` This is a pure refactoring with no behavior changes. Extracted out of rust-lang#70467 r? @eddyb
5461dff
to
098c46d
Compare
The `FnAbi` now knows if the function is allowed to unwind. If a function isn't allowed to unwind, we can use a `call` instead of an `invoke`. This resolves an issue when calling LLVM intrinsics which cannot unwind LLVM will generate an error if you attempt to invoke them so we need to ignore cleanup blocks in codegen and generate a call instead.
098c46d
to
8da26e0
Compare
call
instead of invoke
for functions that cannot unwind
I believe this is ready for review. |
r? @nagisa (LGTM, but I'm not sure if this is going to affect some ongoing ffi-unwind stuff) |
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.
r=me after at least an issue is filled about not generating cleanup blocks in the first place.
if let Some(cleanup) = cleanup { | ||
// If there is a cleanup block and the function we're calling can unwind, then | ||
// do an invoke, otherwise do a call. | ||
if let Some(cleanup) = cleanup.filter(|_| fn_abi.can_unwind) { |
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.
IMO in most instances this should happen way earlier. That is, the cleanup blocks should not be reach codegen in the first place for calls of functions that cannot unwind. This can happen either during MIR construction or afterwards in some clean-up pass.
This piece of code still needs to exist, of course, because fn_abi
information in some cases may only be available after monomorphization, but the test case that changes in this PR does not involve generics...
I’m fine with work to do this happening in some follow-up PR (possibly implemented by somebody else), but in that case at least an issue needs to exist to that effect.
@BatmanAoD It doesn't matter since unwinding from |
@bors r=nagisa |
📌 Commit 8da26e0 has been approved by |
Use `call` instead of `invoke` for functions that cannot unwind The `FnAbi` now knows if the function is allowed to unwind. If a function isn't allowed to unwind, we can use a `call` instead of an `invoke`. This resolves an issue when calling LLVM intrinsics which cannot unwind LLVM will generate an error if you attempt to invoke them so we need to ignore cleanup blocks in codegen and generate a call instead. Fixes rust-lang#69911 r? @eddyb cc @rust-lang/wg-ffi-unwind
Rollup of 6 pull requests Successful merges: - rust-lang#70467 (Use `call` instead of `invoke` for functions that cannot unwind ) - rust-lang#71070 (rustbuild: Remove stage 0 LLD flavor workaround for MSVC) - rust-lang#71167 (big-O notation: parenthesis for function calls, explicit multiplication) - rust-lang#71238 (Miri: fix typo) - rust-lang#71242 (Format Mailmap To Work With GitHub) - rust-lang#71243 (Account for use of `try!()` in 2018 edition and guide users in the right direction) Failed merges: r? @ghost
The
FnAbi
now knows if the function is allowed to unwind. If afunction isn't allowed to unwind, we can use a
call
instead of aninvoke
.This resolves an issue when calling LLVM intrinsics which cannot unwind
LLVM will generate an error if you attempt to invoke them so we need to
ignore cleanup blocks in codegen and generate a call instead.
Fixes #69911
r? @eddyb
cc @rust-lang/wg-ffi-unwind