Skip to content
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

Trait objects missing #[track_caller] shims #74764

Closed
anp opened this issue Jul 25, 2020 · 6 comments · Fixed by #74784
Closed

Trait objects missing #[track_caller] shims #74764

anp opened this issue Jul 25, 2020 · 6 comments · Fixed by #74784
Labels
C-bug Category: This is a bug. F-track_caller `#![feature(track_caller)]` I-unsound Issue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/Soundness P-critical Critical priority regression-from-stable-to-stable Performance or correctness regression from one stable version to another. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@anp
Copy link
Member

anp commented Jul 25, 2020

After reducing a repro of a potential track_caller bug from @yaahc, I get a segfault from this code:

trait Handler {
    fn handle(&self);
}

impl<T> Handler for T {
    #[track_caller]
    fn handle(&self) {
        assert_eq!(std::panic::Location::caller().file(), file!());
    }
}

fn main() {
    let handler: &(dyn Handler) = &5u8;
    handler.handle();
}

This repros for me on my up-to-date checkout as well as for the current beta compiler. I'm not sure whether that makes this a regression from stable to beta, since it's an apparent bug in an API which is first stabilizing in this release.

cc @eddyb

@anp anp added the C-bug Category: This is a bug. label Jul 25, 2020
@jonas-schievink jonas-schievink added F-track_caller `#![feature(track_caller)]` I-unsound Issue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/Soundness labels Jul 25, 2020
@rustbot rustbot added the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Jul 25, 2020
@estebank estebank added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Jul 25, 2020
@lcnr
Copy link
Contributor

lcnr commented Jul 26, 2020

this causes a segfault on stable:

use std::ops::Index;

fn main() {
    let vec = vec![1];
    let handler: &dyn Index<usize, Output = i32> = &vec;
    handler.index(2);
}

results in

thread 'main' panicked at 'index out of bounds: the len is 1 but the index is 2', Segmentation fault (core dumped)

Luckily dyn Index is very rarely used

@lcnr lcnr added the regression-from-stable-to-stable Performance or correctness regression from one stable version to another. label Jul 26, 2020
@anp
Copy link
Member Author

anp commented Jul 26, 2020

Oof! I'm looking at the existing tests and I realize what we missed. We test direct calls to tracked trait methods and we test indirect calls to tracked trait functions (i.e. no receivers), but we don't test indirect calls of trait methods with receivers.

@anp
Copy link
Member Author

anp commented Jul 26, 2020

My immediate suspicion is that trait object vtables aren't going through the reification path we added to Instance::resolve_for_fn_ptr.

@anp anp changed the title Apparent miscompilation of #[track_caller] shims? Trait objects missing #[track_caller] shims Jul 26, 2020
@anp
Copy link
Member Author

anp commented Jul 26, 2020

Thanks to @eddyb for confirming this doesn't seem to affect self-by-val.

@anp
Copy link
Member Author

anp commented Jul 26, 2020

Opened #74784 with a fix, thanks again to @eddyb for help finding the missing call!

@LeSeulArtichaut LeSeulArtichaut added P-critical Critical priority and removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Jul 26, 2020
@LeSeulArtichaut
Copy link
Contributor

Assigning P-critical as discussed as part of the Prioritization WG Procedure.

bors added a commit to rust-lang-ci/rust that referenced this issue Jul 27, 2020
Fix #[track_caller] shims for trait objects.

We were missing an Instance::resolve_for_fn_ptr in resolve_for_vtable.

Closes rust-lang#74764.
@bors bors closed this as completed in 4c710e7 Jul 27, 2020
Mark-Simulacrum pushed a commit to Mark-Simulacrum/rust that referenced this issue Jul 30, 2020
We were missing an Instance::resolve_for_fn_ptr in resolve_for_vtable.

Closes rust-lang#74764.
bors added a commit to rust-lang/miri that referenced this issue Jul 31, 2020
test track_caller on trait objects

Adds a Miri-side test for rust-lang/rust#74764.
bors added a commit to rust-lang/miri that referenced this issue Jul 31, 2020
test track_caller on trait objects

Adds a Miri-side test for rust-lang/rust#74764.
Mark-Simulacrum pushed a commit to Mark-Simulacrum/rust that referenced this issue Aug 7, 2020
We were missing an Instance::resolve_for_fn_ptr in resolve_for_vtable.

Closes rust-lang#74764.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. F-track_caller `#![feature(track_caller)]` I-unsound Issue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/Soundness P-critical Critical priority regression-from-stable-to-stable Performance or correctness regression from one stable version to another. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants