ICE in get_fn_addr_from_dyn, at rust/backend/rust-compile-expr.cc

Open
#4,987 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 3 days

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
42/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
cpp, rust
Domain
compilers

Research direction

The crash is in get_fn_addr_from_dyn in gcc/rust/backend/rust-compile-expr.cc, reached from CompileExpr::visit(MethodCallExpr) around line 1915. Start by reproducing the reduced trait A / fn foo(x: &dyn A) / A.test() case with the crab1 flags listed in the issue, then read how the dyn object type's method is resolved. Done means the reduced case no longer hits the internal error and the method call on the trait object is compiled.

Written by the indexing model from the issue text.

Description

bug

auto-reduced (treereduce-rust):

//@compile-flags: -frust-incomplete-and-experimental-compiler-do-not-use -frust-crate-attr=no_core
trait A {
    fn test(&self);
}

fn foo(x: &dyn A) {
    A.test();
}

original:

//@ run-pass
// Check that the object bound dyn A + 'a: A is preferred over the
// where clause bound dyn A + 'static: A.

#![allow(unused)]

trait A {
    fn test(&self);
}

fn foo(x: &dyn A)
where
    dyn A + 'static: A, // Using this bound would lead to a lifetime error.
{
    A.test();
}

fn main () {}

Version information:

a02e9a643d591708a5de6d506ef75f3405a91a0e

Possibly related line of code:
https://github.com/Rust-GCC/gccrs/blob/a02e9a643d591708a5de6d506ef75f3405a91a0e/gcc/rust/backend/rust-compile-expr.cc#L1983-L1995

Command:
/home/matthias/vcs/github/gccrs/gccrs-build/gcc/crab1 -frust-incomplete-and-experimental-compiler-do-not-use -frust-crate-attr=no_core -frust-crate-attr=feature(no_core)

Program output

crab1: internal compiler error: in get_fn_addr_from_dyn, at rust/backend/rust-compile-expr.cc:1989
0x35dee47 internal_error(char const*, ...)
	../../gcc/diagnostic-global-context.cc:787
0xd2fe75 fancy_abort(char const*, int, char const*)
	../../gcc/diagnostics/context.cc:1813
0x93ba4d Rust::Compile::CompileExpr::get_fn_addr_from_dyn(Rust::TyTy::DynamicObjectType const*, Rust::TyTy::BaseType*, Rust::TyTy::FnType*, tree_node*, unsigned long)
	../../gcc/rust/backend/rust-compile-expr.cc:1989
0x12c1973 Rust::Compile::CompileExpr::visit(Rust::HIR::MethodCallExpr&)
	../../gcc/rust/backend/rust-compile-expr.cc:1915
0x12b59d6 Rust::Compile::CompileExpr::Compile(Rust::HIR::Expr&, Rust::Compile::Context*)
	../../gcc/rust/backend/rust-compile-expr.cc:164
0x12ab5f0 ???
	../../gcc/rust/backend/rust-compile-stmt.h:33
0x12abe7c Rust::Compile::CompileStmt::Compile(Rust::HIR::Stmt*, Rust::Compile::Context*)
	../../gcc/rust/backend/rust-compile-stmt.cc:39
0x12edb8b Rust::Compile::HIRCompileBase::compile_function_body(tree_node*, Rust::HIR::BlockExpr&, Rust::TyTy::BaseType*)
	../../gcc/rust/backend/rust-compile-base.cc:683
0x12ef412 Rust::Compile::HIRCompileBase::compile_function(bool, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, tl::optional<Rust::HIR::SelfParam>&, std::vector<Rust::HIR::FunctionParam, std::allocator<Rust::HIR::FunctionParam> >&, Rust::HIR::FunctionQualifiers const&, Rust::HIR::Visibility&, std::vector<Rust::AST::Attribute, std::allocator<Rust::AST::Attribute> >&, unsigned long, Rust::HIR::BlockExpr*, Rust::Resolver::CanonicalPath const&, Rust::TyTy::FnType*)
	../../gcc/rust/backend/rust-compile-base.cc:922
0x12a9e4d Rust::Compile::CompileItem::visit(Rust::HIR::Function&)
	../../gcc/rust/backend/rust-compile-item.cc:283
0xf98b1b Rust::Compile::CompileItem::compile(Rust::HIR::Item*, Rust::Compile::Context*, Rust::TyTy::BaseType*, unsigned long)
	../../gcc/rust/backend/rust-compile-item.h:37
0xf98b1b Rust::Compile::CompileCrate::go()
	../../gcc/rust/backend/rust-compile.cc:49
0xf98b1b Rust::Compile::CompileCrate::Compile(Rust::HIR::Crate&, Rust::Compile::Context*)
	../../gcc/rust/backend/rust-compile.cc:42
0xf82d9c Rust::Session::compile_crate(char const*)
	../../gcc/rust/rust-session-manager.cc:862
/home/matthias/vcs/github/gccrs/gccrs-build/gcc/crab1 /tmp/icemaker_global_tempdir.2Zk2ZzLJdIQG/rustc_testrunner_tmpdir_reporting.V35g0DJY6vxw/mvce.rs -o/tmp/icemaker_global_tempdir.2Zk2ZzLJdIQG/rustc_testrunner_tmpdir_reporting.V35g0DJY6vxw/binaryname -frust-incomplete-and-experimental-compiler-do-not-use -frust-crate-attr=no_core -frust-crate-attr=feature(no_core)
Please submit a full bug report, with preprocessed source (by using -freport-bug).
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.

Dominant language
C++
Stars
3k
Forks
238
Avg merge
4d 8h
Merged PRs (30d)
31

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Rust-GCC/gccrs

All issues in Rust-GCC/gccrs

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.