-
Notifications
You must be signed in to change notification settings - Fork 13.9k
Refactor the way cg_ssa handles indirect returns(returns via sret).
#144976
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
Open
FractalFir
wants to merge
3
commits into
rust-lang:master
Choose a base branch
from
FractalFir:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -644,7 +644,16 @@ impl<'a, 'gcc, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tc | |
| fn abort(&mut self) { | ||
| let func = self.context.get_builtin_function("abort"); | ||
| let func: RValue<'gcc> = unsafe { std::mem::transmute(func) }; | ||
| self.call(self.type_void(), None, None, func, &[], None, None); | ||
| self.call( | ||
| self.type_void(), | ||
| None, | ||
| None, | ||
| func, | ||
| None, /* abort does not return, so it can't return indirectly. */ | ||
| &[], | ||
| None, | ||
| None, | ||
| ); | ||
| } | ||
|
|
||
| fn assume(&mut self, value: Self::Value) { | ||
|
|
@@ -1340,7 +1349,16 @@ fn try_intrinsic<'a, 'b, 'gcc, 'tcx>( | |
| dest: PlaceRef<'tcx, RValue<'gcc>>, | ||
| ) { | ||
| if bx.sess().panic_strategy() == PanicStrategy::Abort { | ||
| bx.call(bx.type_void(), None, None, try_func, &[data], None, None); | ||
| bx.call( | ||
| bx.type_void(), | ||
| None, | ||
| None, | ||
| try_func, | ||
| None, /* This intrinsic does not return indirectly.*/ | ||
| &[data], | ||
| None, | ||
| None, | ||
| ); | ||
| // Return 0 unconditionally from the intrinsic call; | ||
| // we can never unwind. | ||
| OperandValue::Immediate(bx.const_i32(0)).store(bx, dest); | ||
|
|
@@ -1413,21 +1431,50 @@ fn codegen_gnu_try<'gcc, 'tcx>( | |
| let zero = bx.cx.context.new_rvalue_zero(bx.int_type); | ||
| let ptr = bx.cx.context.new_call(None, eh_pointer_builtin, &[zero]); | ||
| let catch_ty = bx.type_func(&[bx.type_i8p(), bx.type_i8p()], bx.type_void()); | ||
| bx.call(catch_ty, None, None, catch_func, &[data, ptr], None, None); | ||
| bx.call( | ||
| catch_ty, | ||
| None, | ||
| None, | ||
| catch_func, | ||
| None, /* this function can't return indirectly */ | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if there is going to be a comment, then please answer "why can't it?" instead of a statement that it doesn't return indirectly. |
||
| &[data, ptr], | ||
| None, | ||
| None, | ||
| ); | ||
| bx.ret(bx.const_i32(1)); | ||
|
|
||
| // NOTE: the blocks must be filled before adding the try/catch, otherwise gcc will not | ||
| // generate a try/catch. | ||
| // FIXME(antoyo): add a check in the libgccjit API to prevent this. | ||
| bx.switch_to_block(current_block); | ||
| bx.invoke(try_func_ty, None, None, try_func, &[data], then, catch, None, None); | ||
| bx.invoke( | ||
| try_func_ty, | ||
| None, | ||
| None, | ||
| try_func, | ||
| None, /* this function can't return indirectly */ | ||
| &[data], | ||
| then, | ||
| catch, | ||
| None, | ||
| None, | ||
| ); | ||
| }); | ||
|
|
||
| let func = unsafe { std::mem::transmute::<Function<'gcc>, RValue<'gcc>>(func) }; | ||
|
|
||
| // Note that no invoke is used here because by definition this function | ||
| // can't panic (that's what it's catching). | ||
| let ret = bx.call(llty, None, None, func, &[try_func, data, catch_func], None, None); | ||
| let ret = bx.call( | ||
| llty, | ||
| None, | ||
| None, | ||
| func, | ||
| None, /*This function can't return indirectly*/ | ||
| &[try_func, data, catch_func], | ||
| None, | ||
| None, | ||
| ); | ||
| OperandValue::Immediate(ret).store(bx, dest); | ||
| } | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
please break the comment onto the preceding line.