-
Notifications
You must be signed in to change notification settings - Fork 254
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
Remove duplicate remove_outer_deref
s and refactor mod deref
#573
Open
kkysen
wants to merge
5
commits into
tests.refs.fields
Choose a base branch
from
kkysen/tests.refs.fields/remove-outer-deref-refactor
base: tests.refs.fields
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
5 commits
Select commit
Hold shift + click to select a range
30da2a6
Refactored `mod deref` so that most of the functions are implemented …
kkysen 682595e
Combined the two `Rvalue::AddressOf` `match` arms as they're similar …
kkysen 2b7a1b6
Added `apply` to simplify the conditional builder chain.
kkysen f009781
Applied a very similar refactor to the `Rvalue::Ref` `match` arms usi…
kkysen 319656f
`has_outer_deref` is dead code now, so remove it.
kkysen 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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 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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
use anyhow::Context; | ||
use apply::Apply; | ||
use c2rust_analysis_rt::metadata::Metadata; | ||
use c2rust_analysis_rt::mir_loc::{self, EventMetadata, Func, MirLoc, MirLocId, TransferKind}; | ||
use c2rust_analysis_rt::HOOK_FUNCTIONS; | ||
|
@@ -20,7 +21,7 @@ use std::sync::Mutex; | |
|
||
use crate::arg::{ArgKind, InstrumentationArg}; | ||
use crate::hooks::Hooks; | ||
use crate::mir_utils::{has_outer_deref, remove_outer_deref, strip_all_deref}; | ||
use crate::mir_utils::{remove_outer_deref, strip_all_deref, try_remove_outer_deref}; | ||
use crate::point::cast_ptr_to_usize; | ||
use crate::point::InstrumentationAdder; | ||
use crate::point::InstrumentationApplier; | ||
|
@@ -229,25 +230,21 @@ impl<'tcx> Visitor<'tcx> for InstrumentationAdder<'_, 'tcx> { | |
} | ||
} | ||
_ if !is_region_or_unsafe_ptr(value_ty) => {} | ||
Rvalue::AddressOf(_, p) | ||
if has_outer_deref(p) | ||
&& place_ty(&remove_outer_deref(*p, self.tcx())).is_region_ptr() => | ||
{ | ||
let source = remove_outer_deref(*p, self.tcx()); | ||
// Instrument which local's address is taken | ||
self.loc(location.successor_within_block(), copy_fn) | ||
.arg_var(dest) | ||
.source(&source) | ||
.dest(&dest) | ||
.debug_mir(location) | ||
.add_to(self); | ||
} | ||
Rvalue::AddressOf(_, p) => { | ||
// Instrument which local's address is taken | ||
self.loc(location.successor_within_block(), addr_local_fn) | ||
let source = try_remove_outer_deref(*p, self.tcx()) | ||
.filter(|source| place_ty(source).is_region_ptr()); | ||
let func = match source { | ||
Some(_) => copy_fn, | ||
None => addr_local_fn, | ||
}; | ||
self.loc(location.successor_within_block(), func) | ||
.arg_var(dest) | ||
.arg_index_of(p.local) | ||
.source(p) | ||
.apply(|b| match source { | ||
Some(_) => b, | ||
None => b.arg_index_of(p.local), | ||
}) | ||
.source(source.as_ref().unwrap_or(p)) | ||
.dest(&dest) | ||
.debug_mir(location) | ||
.add_to(self); | ||
|
@@ -281,49 +278,30 @@ impl<'tcx> Visitor<'tcx> for InstrumentationAdder<'_, 'tcx> { | |
.debug_mir(location) | ||
.add_to(self); | ||
} | ||
Rvalue::Ref(_, bkind, p) if has_outer_deref(p) => { | ||
Rvalue::Ref(_, bkind, p) => { | ||
// this is a reborrow or field reference, i.e. _2 = &(*_1) | ||
let source = remove_outer_deref(*p, self.tcx()); | ||
if let BorrowKind::Mut { .. } = bkind { | ||
let source = try_remove_outer_deref(*p, self.tcx()); | ||
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. i don't want to combine these, there are more complicated cases incoming and it'll be much clearer if they're separate |
||
let loc = if let BorrowKind::Mut { .. } = bkind { | ||
// Instrument which local's address is taken | ||
self.loc(location, copy_fn) | ||
.arg_addr_of(*p) | ||
.source(&source) | ||
.dest(&dest) | ||
.debug_mir(location) | ||
.add_to(self); | ||
location | ||
} else { | ||
// Instrument immutable borrows by tracing the reference itself | ||
self.loc(location.successor_within_block(), copy_fn) | ||
.arg_var(dest) | ||
.source(&source) | ||
.dest(&dest) | ||
.debug_mir(location) | ||
.add_to(self); | ||
location.successor_within_block() | ||
}; | ||
} | ||
Rvalue::Ref(_, bkind, p) if !p.is_indirect() => { | ||
// this is a reborrow or field reference, i.e. _2 = &(*_1) | ||
let source = remove_outer_deref(*p, self.tcx()); | ||
if let BorrowKind::Mut { .. } = bkind { | ||
// Instrument which local's address is taken | ||
self.loc(location, addr_local_fn) | ||
.arg_addr_of(*p) | ||
.arg_index_of(p.local) | ||
.source(&source) | ||
.dest(&dest) | ||
.debug_mir(location) | ||
.add_to(self); | ||
} else { | ||
// Instrument immutable borrows by tracing the reference itself | ||
self.loc(location.successor_within_block(), addr_local_fn) | ||
.arg_var(dest) | ||
.arg_index_of(p.local) | ||
.source(&source) | ||
.dest(&dest) | ||
.debug_mir(location) | ||
.add_to(self); | ||
let func = match source { | ||
Some(_) => copy_fn, | ||
None => addr_local_fn, | ||
}; | ||
self.loc(loc, func) | ||
.arg_addr_of(*p) | ||
.apply(|b| match source { | ||
Some(_) => b, | ||
None => b.arg_index_of(p.local), | ||
}) | ||
.source(source.as_ref().unwrap_or(p)) | ||
.dest(&dest) | ||
.debug_mir(location) | ||
.add_to(self); | ||
} | ||
_ => (), | ||
} | ||
|
This file contains 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 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
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.
i don't want to combine these, there are more complicated cases incoming and it'll be much clearer if they're separate