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

Segementation fault when calling a method #39292

Closed
ulysseB opened this issue Jan 25, 2017 · 6 comments
Closed

Segementation fault when calling a method #39292

ulysseB opened this issue Jan 25, 2017 · 6 comments
Assignees
Labels
I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics. P-high High 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

@ulysseB
Copy link

ulysseB commented Jan 25, 2017

The following code generates a segfault when executed.

trait Foo<T> {
    fn print<'a>(&'a self) where T: 'a { println!("foo"); }
}

impl<'a> Foo<&'a ()> for () { }

trait Bar: for<'a> Foo<&'a ()> { }

impl Bar for () {}

fn main() {
    (&() as &Bar).print(); // Segfault
}

rust version:

rustc 1.16.0-nightly (9761b17d5 2017-01-21)
binary: rustc
commit-hash: 9761b17d558d0c980d4d2d5a0baba54f2bc6b63a
commit-date: 2017-01-21
host: x86_64-unknown-linux-gnu
release: 1.16.0-nightly
LLVM version: 3.9
@sfackler sfackler added I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jan 25, 2017
@jonas-schievink
Copy link
Contributor

Removing where T: 'a makes it work. The binary seems not to include the called method.

@jonas-schievink
Copy link
Contributor

jonas-schievink commented Jan 25, 2017

Suspicious code:

// Some methods cannot be called on an object; skip those.
if !tcx.is_vtable_safe_method(trait_ref.def_id(), &trait_method) {
debug!("get_vtable_methods: not vtable safe");
return None;
}
// the method may have some early-bound lifetimes, add
// regions for those
let substs = Substs::for_item(tcx, def_id,
|_, _| tcx.mk_region(ty::ReErased),
|def, _| trait_ref.substs().type_for_def(def));
// It's possible that the method relies on where clauses that
// do not hold for this particular set of type parameters.
// Note that this method could then never be called, so we
// do not want to try and trans it, in that case (see #23435).
let predicates = tcx.item_predicates(def_id).instantiate_own(tcx, substs);
if !normalize_and_test_predicates(tcx, predicates.predicates) {
debug!("get_vtable_methods: predicates do not hold");
return None;
}
(seems to test whether T: 'erased holds to decide if the method can ever be called)

EDIT: 'erased doesn't matter

@nikomatsakis nikomatsakis added the regression-from-stable-to-stable Performance or correctness regression from one stable version to another. label Jan 26, 2017
@nikomatsakis
Copy link
Contributor

nikomatsakis commented Jan 26, 2017

@nagisa says this is a regression, as 1.10 (at least) executed this successfully. @eddyb says he made some recent improvements (#34419) might be the problem here, but they don't look that related.

@nikomatsakis
Copy link
Contributor

triage: P-high

Regression.

@rust-highfive rust-highfive added the P-high High priority label Jan 26, 2017
@nikomatsakis nikomatsakis self-assigned this Jan 26, 2017
@arielb1
Copy link
Contributor

arielb1 commented Feb 9, 2017

This patch fixes the issue:

diff --git a/src/librustc/traits/mod.rs b/src/librustc/traits/mod.rs
index 4893e24091..71d67b106a 100644
--- a/src/librustc/traits/mod.rs
+++ b/src/librustc/traits/mod.rs
@@ -628,6 +628,7 @@ pub fn get_vtable_methods<'a, 'tcx>(
                                           |_, _| tcx.mk_region(ty::ReErased),
                                           |def, _| trait_ref.substs().type_for_def(def));
 
+            let substs = tcx.erase_late_bound_regions_and_normalize(&ty::Binder(substs));
             // It's possible that the method relies on where clauses that
             // do not hold for this particular set of type parameters.
             // Note that this method could then never be called, so we

@nikomatsakis
Copy link
Contributor

Fix in #39887

bors added a commit that referenced this issue Feb 18, 2017
erase late bound regions in `get_vtable_methods()`

Higher-ranked object types can otherwise cause late-bound regions to
sneak into the substs, leading to the false conclusion that some method
is unreachable.

r? @arielb1, who wrote the heart of this patch anyhow

Fixes #39292
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics. P-high High 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

No branches or pull requests

6 participants