Skip to content

add test for fields of references #567

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

Merged
merged 8 commits into from
Aug 3, 2022
Merged

add test for fields of references #567

merged 8 commits into from
Aug 3, 2022

Conversation

aneksteind
Copy link
Contributor

No description provided.

@aneksteind aneksteind changed the base branch from feat.pdg.ref.2 to master August 1, 2022 22:01
@aneksteind aneksteind requested a review from spernsteiner August 1, 2022 22:25
@@ -241,10 +241,12 @@ impl<'tcx> Visitor<'tcx> for InstrumentationAdder<'_, 'tcx> {
statement_index: location.statement_index + 1,
..location
};

let source = remove_outer_deref(*p, self.tcx());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove_outer_deref(*p, self.tcx()) is already computed above on line 238:

                    && place_ty(&remove_outer_deref(*p, self.tcx())).is_region_ptr() =>

Could you de-duplicate this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe a try_remove_outer_deref would be useful here:

/// Try to strip the initital [`Deref`](ProjectionElem::Deref)
/// from a [`projection`](PlaceRef::projection) sequence.
pub fn try_remove_outer_deref<'tcx>(p: Place<'tcx>, tcx: TyCtxt<'tcx>) -> Option<Place<'tcx>> {
    // Remove outer deref if present
    match p.as_ref() {
        PlaceRef {
            local,
            projection: &[ref base @ .., ProjectionElem::Deref],
        } => Some(Place {
            local,
            projection: tcx.intern_place_elems(base),
        }),
        _ => None,
    }
}

/// Strip the initital [`Deref`](ProjectionElem::Deref)
/// from a [`projection`](PlaceRef::projection) sequence
/// if there is one.
pub fn remove_outer_deref<'tcx>(p: Place<'tcx>, tcx: TyCtxt<'tcx>) -> Place<'tcx> {
    try_remove_outer_deref(p, tcx).unwrap_or(p)
}

Copy link
Contributor

@kkysen kkysen Aug 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could do

            Rvalue::AddressOf(_, p)
                if let Some(source) = try_remove_outer_deref(*p, self.tcx())
                && place_ty(source).is_region_ptr() =>
            {
                // 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);
            }

but that requires #![feature(if_let_guard, let_chains)]. It might be too clunky without those, I think.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about the changes in #573?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think #573 is probably too big for the scope of this PR, but keep it in my mind for after merging this PR.

Copy link
Contributor

@kkysen kkysen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my improvement PRs.

Copy link
Contributor

@fw-immunant fw-immunant left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved conditional on fixing the calloc(0, ...) in the test case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants