-
-
Notifications
You must be signed in to change notification settings - Fork 14.9k
Emit retags in codegen to support BorrowSanitizer. #155965
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
Closed
Closed
Changes from all commits
Commits
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
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
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 |
|---|---|---|
|
|
@@ -264,6 +264,12 @@ impl<'a, 'tcx> TerminatorCodegenHelper<'tcx> { | |
| bx.lifetime_end(tmp, size); | ||
| } | ||
| fx.store_return(bx, ret_dest, &fn_abi.ret, invokeret); | ||
|
|
||
| // If the return value has variants that needed to be retagged, | ||
| // then we might be in a different basic block now. | ||
| // Update the cached block for `target` to point to this new | ||
| // block, where codegen will continue. | ||
| fx.cached_llbbs[target] = CachedLlbb::Some(bx.llbb()); | ||
| } | ||
| MergingSucc::False | ||
| } else { | ||
|
|
@@ -1055,21 +1061,23 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { | |
| let result_layout = | ||
| self.cx.layout_of(self.monomorphized_place_ty(destination.as_ref())); | ||
|
|
||
| let needs_retag = !destination.is_indirect_first_projection(); | ||
|
|
||
| let return_dest = if result_layout.is_zst() { | ||
| ReturnDest::Nothing | ||
| } else if let Some(index) = destination.as_local() { | ||
| match self.locals[index] { | ||
| LocalRef::Place(dest) => ReturnDest::Store(dest), | ||
| LocalRef::Place(dest) => ReturnDest::Store(dest, needs_retag), | ||
| LocalRef::UnsizedPlace(_) => bug!("return type must be sized"), | ||
| LocalRef::PendingOperand => { | ||
| // Handle temporary places, specifically `Operand` ones, as | ||
| // they don't have `alloca`s. | ||
| ReturnDest::DirectOperand(index) | ||
| ReturnDest::DirectOperand(index, needs_retag) | ||
| } | ||
| LocalRef::Operand(_) => bug!("place local already assigned to"), | ||
| } | ||
| } else { | ||
| ReturnDest::Store(self.codegen_place(bx, destination.as_ref())) | ||
| ReturnDest::Store(self.codegen_place(bx, destination.as_ref()), needs_retag) | ||
| }; | ||
|
|
||
| let args = | ||
|
|
@@ -2039,6 +2047,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { | |
| if fn_ret.is_ignore() { | ||
| return ReturnDest::Nothing; | ||
| } | ||
| let needs_retag = !dest.is_indirect_first_projection(); | ||
| let dest = if let Some(index) = dest.as_local() { | ||
| match self.locals[index] { | ||
| LocalRef::Place(dest) => dest, | ||
|
|
@@ -2052,9 +2061,9 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { | |
| let tmp = PlaceRef::alloca(bx, fn_ret.layout); | ||
| tmp.storage_live(bx); | ||
| llargs.push(tmp.val.llval); | ||
| ReturnDest::IndirectOperand(tmp, index) | ||
| ReturnDest::IndirectOperand(tmp, index, needs_retag) | ||
| } else { | ||
| ReturnDest::DirectOperand(index) | ||
| ReturnDest::DirectOperand(index, needs_retag) | ||
| }; | ||
| } | ||
| LocalRef::Operand(_) => { | ||
|
|
@@ -2077,7 +2086,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { | |
| llargs.push(dest.val.llval); | ||
| ReturnDest::Nothing | ||
| } else { | ||
| ReturnDest::Store(dest) | ||
| ReturnDest::Store(dest, needs_retag) | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -2090,19 +2099,27 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { | |
| llval: Bx::Value, | ||
| ) { | ||
| use self::ReturnDest::*; | ||
|
|
||
| let retags_enabled = bx.tcx().sess.opts.unstable_opts.codegen_emit_retag.is_some(); | ||
| match dest { | ||
| Nothing => (), | ||
| Store(dst) => bx.store_arg(ret_abi, llval, dst), | ||
| IndirectOperand(tmp, index) => { | ||
| let op = bx.load_operand(tmp); | ||
| Store(dst, needs_retag) => { | ||
| bx.store_arg(ret_abi, llval, dst); | ||
| if retags_enabled && needs_retag { | ||
| self.codegen_retag_place(bx, dst, false); | ||
| } | ||
| } | ||
| IndirectOperand(tmp, index, needs_retag) => { | ||
| let mut op = bx.load_operand(tmp); | ||
| if retags_enabled && needs_retag { | ||
| op = self.codegen_retag_operand(bx, op, false); | ||
| } | ||
| tmp.storage_dead(bx); | ||
| self.overwrite_local(index, LocalRef::Operand(op)); | ||
| self.debug_introduce_local(bx, index); | ||
| } | ||
| DirectOperand(index) => { | ||
| DirectOperand(index, needs_retag) => { | ||
| // If there is a cast, we have to store and reload. | ||
| let op = if let PassMode::Cast { .. } = ret_abi.mode { | ||
| let mut op = if let PassMode::Cast { .. } = ret_abi.mode { | ||
| let tmp = PlaceRef::alloca(bx, ret_abi.layout); | ||
| tmp.storage_live(bx); | ||
| bx.store_arg(ret_abi, llval, tmp); | ||
|
|
@@ -2112,6 +2129,9 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { | |
| } else { | ||
| OperandRef::from_immediate_or_packed_pair(bx, llval, ret_abi.layout) | ||
| }; | ||
| if retags_enabled && needs_retag { | ||
| op = self.codegen_retag_operand(bx, op, false); | ||
| } | ||
| self.overwrite_local(index, LocalRef::Operand(op)); | ||
| self.debug_introduce_local(bx, index); | ||
| } | ||
|
|
@@ -2123,11 +2143,11 @@ enum ReturnDest<'tcx, V> { | |
| /// Do nothing; the return value is indirect or ignored. | ||
| Nothing, | ||
| /// Store the return value to the pointer. | ||
| Store(PlaceRef<'tcx, V>), | ||
| Store(PlaceRef<'tcx, V>, bool), | ||
|
Member
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. Mind giving these fields names? A plain bool doesn't explain what it means. |
||
| /// Store an indirect return value to an operand local place. | ||
| IndirectOperand(PlaceRef<'tcx, V>, mir::Local), | ||
| IndirectOperand(PlaceRef<'tcx, V>, mir::Local, bool), | ||
| /// Store a direct return value to an operand local place. | ||
| DirectOperand(mir::Local), | ||
| DirectOperand(mir::Local, bool), | ||
| } | ||
|
|
||
| fn load_cast<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( | ||
|
|
||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
A pointer to a constant array, right?
View changes since the review