segfault tree_class_check / build_pointer_type_for_mode

Open
#4,990 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
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
cpp, rust
Domain
compilers

Research direction

Start with the backtrace: the crash is a null or invalid tree in address_expression (gcc/rust/backend/rust-compile-base.cc:631), reached from coerce_to_dyn_object (rust-compile.cc:204) via resolve_adjustments (rust-compile-expr.cc:2591). Build crab1, then run the minimal reproducer with the -frust-crate-attr=no_core flags to confirm the segfault. Done means the reproducer compiles without an internal compiler error and the dyn coercion of &mut bar.writer produces correct code.

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 Aaa {}

impl<'a> Aaa for &'a mut (Aaa + 'a) {}

struct Bar<'a> {
    writer: &'a mut (Aaa + 'a),
}

fn baz(_: &mut Aaa) {}

fn foo<'a>(mut bar: Bar<'a>) {
    baz(&mut bar.writer);
}

original:

// Copyright 2014 The Rust Project<!--
File: /tmp/im/gcc/issue-17771_fc821441330a5277fbd95653170fca71b33d8003.rs
-->

auto-reduced (treereduce-rust):
````rust
//@compile-flags: -frust-incomplete-and-experimental-compiler-do-not-use -frust-crate-attr=no_core
//

trait Aaa {}

impl<'a> Aaa for &'a mut (Aaa + 'a) {}

struct Bar<'a> {
    writer: &'a mut (Aaa + 'a),
}

fn baz(_: &mut Aaa) {}

fn foo<'a>(mut bar: Bar<'a>) {
    baz(&mut bar.writer);
}

original:

// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// pretty-expanded FIXME #23616

trait Aaa { fn dummy(&self) { } }

impl<'a> Aaa for &'a mut (Aaa + 'a) {}

struct Bar<'a> {
    writer: &'a mut (Aaa + 'a),
}

fn baz(_: &mut Aaa) {
}

fn foo<'a>(mut bar: Bar<'a>) {
    baz(&mut bar.writer);
}

fn main() {
}

Version information:

a02e9a643d591708a5de6d506ef75f3405a91a0e

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: Segmentation fault
0x35dee47 internal_error(char const*, ...)
	../../gcc/diagnostic-global-context.cc:787
0x1b9a97f crash_signal
	../../gcc/toplev.cc:325
0x202b570 tree_class_check(tree_node*, tree_code_class, char const*, int, char const*)
	../../gcc/tree.h:3985
0x202b570 build_pointer_type_for_mode(tree_node*, machine_mode, bool)
	../../gcc/tree.cc:7237
0x12edaec Rust::Compile::HIRCompileBase::address_expression(tree_node*, unsigned long, tree_node*)
	../../gcc/rust/backend/rust-compile-base.cc:631
0xf9a6d0 Rust::Compile::HIRCompileBase::coerce_to_dyn_object(tree_node*, Rust::TyTy::BaseType*, Rust::TyTy::DynamicObjectType const*, unsigned long)
	../../gcc/rust/backend/rust-compile.cc:204
0x12c11f0 Rust::Compile::HIRCompileBase::resolve_adjustments(std::vector<Rust::Resolver::Adjustment, std::allocator<Rust::Resolver::Adjustment> >&, tree_node*, unsigned long)
	../../gcc/rust/backend/rust-compile-expr.cc:2591
0xf98ce3 Rust::Compile::HIRCompileBase::coercion_site(unsigned int, tree_node*, Rust::TyTy::BaseType*, Rust::TyTy::BaseType*, unsigned long, unsigned long)
	../../gcc/rust/backend/rust-compile.cc:67
0x12c3d30 Rust::Compile::CompileExpr::visit(Rust::HIR::CallExpr&)
	../../gcc/rust/backend/rust-compile-expr.cc:1820
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.gDdyZYBrYJLi/rustc_testrunner_tmpdir_reporting.wdjSE3GP9BIT/mvce.rs -o/tmp/icemaker_global_tempdir.gDdyZYBrYJLi/rustc_testrunner_tmpdir_reporting.wdjSE3GP9BIT/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.

Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// pretty-expanded FIXME #23616

trait Aaa { fn dummy(&self) { } }

impl<'a> Aaa for &'a mut (Aaa + 'a) {}

struct Bar<'a> {
writer: &'a mut (Aaa + 'a),
}

fn baz(_: &mut Aaa) {
}

fn foo<'a>(mut bar: Bar<'a>) {
baz(&mut bar.writer);
}

fn main() {
}


Version information:

a02e9a643d591708a5de6d506ef75f3405a91a0e



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)`

<details><summary><strong>Program output</strong></summary>
<p>

```
crab1: internal compiler error: Segmentation fault
0x35dee47 internal_error(char const*, ...)
	../../gcc/diagnostic-global-context.cc:787
0x1b9a97f crash_signal
	../../gcc/toplev.cc:325
0x202b570 tree_class_check(tree_node*, tree_code_class, char const*, int, char const*)
	../../gcc/tree.h:3985
0x202b570 build_pointer_type_for_mode(tree_node*, machine_mode, bool)
	../../gcc/tree.cc:7237
0x12edaec Rust::Compile::HIRCompileBase::address_expression(tree_node*, unsigned long, tree_node*)
	../../gcc/rust/backend/rust-compile-base.cc:631
0xf9a6d0 Rust::Compile::HIRCompileBase::coerce_to_dyn_object(tree_node*, Rust::TyTy::BaseType*, Rust::TyTy::DynamicObjectType const*, unsigned long)
	../../gcc/rust/backend/rust-compile.cc:204
0x12c11f0 Rust::Compile::HIRCompileBase::resolve_adjustments(std::vector<Rust::Resolver::Adjustment, std::allocator<Rust::Resolver::Adjustment> >&, tree_node*, unsigned long)
	../../gcc/rust/backend/rust-compile-expr.cc:2591
0xf98ce3 Rust::Compile::HIRCompileBase::coercion_site(unsigned int, tree_node*, Rust::TyTy::BaseType*, Rust::TyTy::BaseType*, unsigned long, unsigned long)
	../../gcc/rust/backend/rust-compile.cc:67
0x12c3d30 Rust::Compile::CompileExpr::visit(Rust::HIR::CallExpr&)
	../../gcc/rust/backend/rust-compile-expr.cc:1820
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.gDdyZYBrYJLi/rustc_testrunner_tmpdir_reporting.wdjSE3GP9BIT/mvce.rs -o/tmp/icemaker_global_tempdir.gDdyZYBrYJLi/rustc_testrunner_tmpdir_reporting.wdjSE3GP9BIT/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.

```

</p>
</details>


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.