Rust-GCC / Rust-GCC/gccrs

segfault in NodeMapping::get_nodeid()

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

Nobody has claimed this yet.

bug
Dominant language
C++
Stars
2.9k
Forks
231
Avg merge
19h 55m
Merged PRs (30d)
67

Description

auto-reduced (treereduce-rust):

//@compile-flags: -frust-debug -frust-incomplete-and-experimental-compiler-do-not-use
struct DataType {
    data: *mut (),
}

static DATA: DataType = DataType {
    data: unsafe { &mut DATA },
};

original:

struct DataType {
    data: *mut (),
}

unsafe impl DataType for DataType {}

static mut EXTRA_DATA: () = ();

static DATA : DataType = DataType {
    data: unsafe { &mut DATA }
};

fn main() {
}

Version information:

5a762b9243e834d69f90985950f4ef330f16b34f

Command:
/home/matthias/vcs/github/gccrs/gccrs-build/gcc/crab1 -frust-debug -frust-incomplete-and-experimental-compiler-do-not-use

Program output

crab1: note: Preparing to parse files. 
crab1: note: Attempting to parse file: /tmp/icemaker_global_tempdir.CmTzlVK6SkSa/rustc_testrunner_tmpdir_reporting.AVHRg2g2uLQ9/mvce.rs
crab1: note: beginning null denotation identifier handling
crab1: note: parsing null denotation after path
crab1: note: values of lookahead: 'identifier' ':' 'unsafe' '{' 
crab1: note: can be struct expr: 'true', not a block: 'false'
crab1: note: beginning null denotation identifier handling
crab1: note: parsing null denotation after path
crab1: note: struct/enum expr field validated to not be null
crab1: note: struct/enum expr field pushed back
crab1: note: struct/enum expr fields comma skipped 
crab1: note: struct/enum expr about to parse struct base 
crab1: note: struct/enum expr skipped right curly - done and ready to return
crab1: note: inferred crate name: mvce
crab1: note: SUCCESSFULLY PARSED CRATE 
crab1: note: ran register_plugins (with no body)
crab1: note: SUCCESSFULLY REGISTERED PLUGINS 
crab1: note: started injection
crab1: note: finished injection
crab1: note: SUCCESSFULLY FINISHED INJECTION 
crab1: note: started expansion
crab1: note: popping link
crab1: note: popping link
crab1: note: current_rib: k: str, v: (S)[] (NS)[82] (G)[]
crab1: note: current_rib: k: char, v: (S)[] (NS)[81] (G)[]
crab1: note: current_rib: k: isize, v: (S)[] (NS)[80] (G)[]
crab1: note: current_rib: k: u8, v: (S)[] (NS)[67] (G)[]
crab1: note: current_rib: k: u64, v: (S)[] (NS)[70] (G)[]
crab1: note: current_rib: k: u16, v: (S)[] (NS)[68] (G)[]
crab1: note: current_rib: k: u32, v: (S)[] (NS)[69] (G)[]
crab1: note: current_rib: k: i16, v: (S)[] (NS)[73] (G)[]
crab1: note: current_rib: k: !, v: (S)[] (NS)[83] (G)[]
crab1: note: current_rib: k: u128, v: (S)[] (NS)[71] (G)[]
crab1: note: current_rib: k: bool, v: (S)[] (NS)[66] (G)[]
crab1: note: current_rib: k: i32, v: (S)[] (NS)[74] (G)[]
crab1: note: current_rib: k: f32, v: (S)[] (NS)[77] (G)[]
crab1: note: current_rib: k: i8, v: (S)[] (NS)[72] (G)[]
crab1: note: current_rib: k: i64, v: (S)[] (NS)[75] (G)[]
crab1: note: current_rib: k: i128, v: (S)[] (NS)[76] (G)[]
crab1: note: current_rib: k: usize, v: (S)[] (NS)[79] (G)[]
crab1: note: current_rib: k: f64, v: (S)[] (NS)[78] (G)[]
crab1: note: popping link
crab1: note: inserting link: Link(7 [DataType]): existed? no
crab1: note: inserting link: Link(7 [DataType]): existed? no
crab1: note: inserting link: Link(7 [DataType]): existed? no
crab1: note: popping link
crab1: note: popping link
crab1: note: popping link
crab1: note: inserting link: Link(23 [<anon>]): existed? no
crab1: note: inserting link: Link(23 [<anon>]): existed? no
crab1: note: inserting link: Link(23 [<anon>]): existed? no
crab1: note: inserting link: Link(19 [<anon>]): existed? no
crab1: note: inserting link: Link(19 [<anon>]): existed? no
crab1: note: inserting link: Link(19 [<anon>]): existed? no
crab1: note: popping link
crab1: note: popping link
crab1: note: popping link
crab1: note: popping link
crab1: note: new cursor: k: DATA, v: (S)[] (NS)[23] (G)[]
crab1: note: popping link
crab1: note: new cursor: k: DataType, v: (S)[] (NS)[7] (G)[]
crab1: note: popping link
crab1: note: inserting link: Link(7 [DataType]): existed? yes
crab1: note: inserting link: Link(7 [DataType]): existed? yes
crab1: note: inserting link: Link(7 [DataType]): existed? yes
crab1: note: popping link
crab1: note: new cursor: k: DATA, v: (S)[] (NS)[23] (G)[]
crab1: note: popping link
crab1: note: new cursor: k: DataType, v: (S)[] (NS)[7] (G)[]
crab1: note: popping link
crab1: note: inserting link: Link(23 [<anon>]): existed? yes
crab1: note: inserting link: Link(23 [<anon>]): existed? yes
crab1: note: inserting link: Link(23 [<anon>]): existed? yes
crab1: note: inserting link: Link(19 [<anon>]): existed? yes
crab1: note: inserting link: Link(19 [<anon>]): existed? yes
crab1: note: inserting link: Link(19 [<anon>]): existed? yes
crab1: note: popping link
crab1: note: popping link
crab1: note: popping link
crab1: note: popping link
crab1: note: new cursor: k: DATA, v: (S)[] (NS)[23] (G)[]
crab1: note: popping link
crab1: note: new cursor: k: DataType, v: (S)[] (NS)[7] (G)[]
crab1: note: popping link
crab1: note: inserting link: Link(7 [DataType]): existed? yes
crab1: note: inserting link: Link(7 [DataType]): existed? yes
crab1: note: inserting link: Link(7 [DataType]): existed? yes
crab1: note: popping link
crab1: note: new cursor: k: DATA, v: (S)[] (NS)[23] (G)[]
crab1: note: popping link
crab1: note: new cursor: k: DataType, v: (S)[] (NS)[7] (G)[]
crab1: note: popping link
crab1: note: inserting link: Link(23 [<anon>]): existed? yes
crab1: note: inserting link: Link(23 [<anon>]): existed? yes
crab1: note: inserting link: Link(23 [<anon>]): existed? yes
crab1: note: inserting link: Link(19 [<anon>]): existed? yes
crab1: note: inserting link: Link(19 [<anon>]): existed? yes
crab1: note: inserting link: Link(19 [<anon>]): existed? yes
crab1: note: popping link
crab1: note: popping link
crab1: note: popping link
crab1: note: popping link
crab1: note: new cursor: k: DATA, v: (S)[] (NS)[23] (G)[]
crab1: note: popping link
crab1: note: new cursor: k: DataType, v: (S)[] (NS)[7] (G)[]
crab1: note: popping link
crab1: note: inserting link: Link(7 [DataType]): existed? yes
crab1: note: inserting link: Link(7 [DataType]): existed? yes
crab1: note: inserting link: Link(7 [DataType]): existed? yes
crab1: note: popping link
crab1: note: new cursor: k: DATA, v: (S)[] (NS)[23] (G)[]
crab1: note: popping link
crab1: note: new cursor: k: DataType, v: (S)[] (NS)[7] (G)[]
crab1: note: popping link
crab1: note: inserting link: Link(23 [<anon>]): existed? yes
crab1: note: inserting link: Link(23 [<anon>]): existed? yes
crab1: note: inserting link: Link(23 [<anon>]): existed? yes
crab1: note: inserting link: Link(19 [<anon>]): existed? yes
crab1: note: inserting link: Link(19 [<anon>]): existed? yes
crab1: note: inserting link: Link(19 [<anon>]): existed? yes
crab1: note: popping link
crab1: note: popping link
crab1: note: popping link
crab1: note: popping link
crab1: note: new cursor: k: DATA, v: (S)[] (NS)[23] (G)[]
crab1: note: popping link
crab1: note: new cursor: k: DataType, v: (S)[] (NS)[7] (G)[]
crab1: note: popping link
crab1: note: inserting link: Link(7 [DataType]): existed? yes
crab1: note: inserting link: Link(7 [DataType]): existed? yes
crab1: note: inserting link: Link(7 [DataType]): existed? yes
crab1: note: popping link
crab1: note: new cursor: k: DATA, v: (S)[] (NS)[23] (G)[]
crab1: note: popping link
crab1: note: new cursor: k: DataType, v: (S)[] (NS)[7] (G)[]
crab1: note: popping link
crab1: note: inserting link: Link(23 [<anon>]): existed? yes
crab1: note: inserting link: Link(23 [<anon>]): existed? yes
crab1: note: inserting link: Link(23 [<anon>]): existed? yes
crab1: note: inserting link: Link(19 [<anon>]): existed? yes
crab1: note: inserting link: Link(19 [<anon>]): existed? yes
crab1: note: inserting link: Link(19 [<anon>]): existed? yes
crab1: note: popping link
crab1: note: popping link
crab1: note: popping link
crab1: note: popping link
crab1: note: new cursor: k: DATA, v: (S)[] (NS)[23] (G)[]
crab1: note: popping link
crab1: note: new cursor: k: DataType, v: (S)[] (NS)[7] (G)[]
crab1: note: popping link
crab1: note: finished expansion
crab1: note: SUCCESSFULLY FINISHED EXPANSION 
crab1: note: inserting link: Link(7 [DataType]): existed? yes
crab1: note: inserting link: Link(7 [DataType]): existed? yes
crab1: note: inserting link: Link(7 [DataType]): existed? yes
crab1: note: popping link
crab1: note: new cursor: k: DATA, v: (S)[] (NS)[23] (G)[]
crab1: note: popping link
crab1: note: new cursor: k: DataType, v: (S)[] (NS)[7] (G)[]
crab1: note: popping link
crab1: note: inserting link: Link(23 [<anon>]): existed? yes
crab1: note: inserting link: Link(23 [<anon>]): existed? yes
crab1: note: inserting link: Link(23 [<anon>]): existed? yes
crab1: note: inserting link: Link(19 [<anon>]): existed? yes
crab1: note: inserting link: Link(19 [<anon>]): existed? yes
crab1: note: inserting link: Link(19 [<anon>]): existed? yes
crab1: note: popping link
crab1: note: popping link
crab1: note: popping link
crab1: note: popping link
crab1: note: new cursor: k: DATA, v: (S)[] (NS)[23] (G)[]
crab1: note: popping link
crab1: note: new cursor: k: DataType, v: (S)[] (NS)[7] (G)[]
crab1: note: popping link
crab1: note: add_type_constraints: DataType{DataType {data:* mut ()}}
crab1: note: 	add_constraint_from_ty: * mut () with v=+
crab1: note: 	add_constraint_from_ty: () with v=+
crab1: note: 	add_constraint_from_ty: () with v=*
crab1: note: {ARTHUR}: Path visited: DataType
/tmp/icemaker_global_tempdir.CmTzlVK6SkSa/rustc_testrunner_tmpdir_reporting.AVHRg2g2uLQ9/mvce.rs:5:14: note: root resolved type-path to: [DataType]
    5 | static DATA: DataType = DataType {
      |              ^~~~~~~~
/tmp/icemaker_global_tempdir.CmTzlVK6SkSa/rustc_testrunner_tmpdir_reporting.AVHRg2g2uLQ9/mvce.rs:5:1: note: resolved item {52} to
    5 | static DATA: DataType = DataType {
      | ^~~~~~
/tmp/icemaker_global_tempdir.CmTzlVK6SkSa/rustc_testrunner_tmpdir_reporting.AVHRg2g2uLQ9/mvce.rs:6:25: error: cannot find value ‘DATA’ in this scope [E0425]
    6 |     data: unsafe { &mut DATA },
      |                         ^~~~
crab1: note: coercion_site id={50} expected={* mut ()} expr={<tyty::error>}
crab1: note: coercion_site id={52} expected={DataType} expr={DataType}
crab1: note: coerce_unsized(source={DataType}, target={DataType})
crab1: note: do_coercion default unify and infer expected: DataType receiver DataType
/tmp/icemaker_global_tempdir.CmTzlVK6SkSa/rustc_testrunner_tmpdir_reporting.AVHRg2g2uLQ9/mvce.rs:5:1: note: begin unify_site_and commit true infer false check_bounds true id={51} expected={DataType} expr={DataType}
    5 | static DATA: DataType = DataType {
      | ^~~~~~
crab1: note: unify::go ltype={DataType} rtype={DataType}
crab1: note: unify::go ltype={* mut ()} rtype={* mut ()}
crab1: note: unify::go ltype={()} rtype={()}
/tmp/icemaker_global_tempdir.CmTzlVK6SkSa/rustc_testrunner_tmpdir_reporting.AVHRg2g2uLQ9/mvce.rs:5:1: note: unify_site_and done ok=true commit true infer false id={51} expected={DataType} expr={DataType}
    5 | static DATA: DataType = DataType {
      | ^~~~~~
crab1: note: coerce_default_unify(a={DataType}, b={DataType})
/tmp/icemaker_global_tempdir.CmTzlVK6SkSa/rustc_testrunner_tmpdir_reporting.AVHRg2g2uLQ9/mvce.rs:5:1: note: begin unify_site_and commit true infer true check_bounds true id={52} expected={DataType} expr={DataType}
    5 | static DATA: DataType = DataType {
      | ^~~~~~
crab1: note: unify::go ltype={DataType} rtype={DataType}
crab1: note: unify::go ltype={* mut ()} rtype={* mut ()}
crab1: note: unify::go ltype={()} rtype={()}
/tmp/icemaker_global_tempdir.CmTzlVK6SkSa/rustc_testrunner_tmpdir_reporting.AVHRg2g2uLQ9/mvce.rs:5:1: note: unify_site_and done ok=true commit true infer true id={52} expected={DataType} expr={DataType}
    5 | static DATA: DataType = DataType {
      | ^~~~~~
crab1: note: coercion_site id={50} expected={* mut ()} expr={&mut DataType}
crab1: note: coerce_unsized(source={&mut DataType}, target={* mut ()})
crab1: note: coerce_unsafe_ptr(receiver={&mut DataType}, expected={* mut ()})
crab1: note: coerce_unsafe_ptr unify-site
/tmp/icemaker_global_tempdir.CmTzlVK6SkSa/rustc_testrunner_tmpdir_reporting.AVHRg2g2uLQ9/mvce.rs:6:5: note: begin unify_site_and commit true infer false check_bounds true id={49} expected={* mut ()} expr={* mut DataType}
    6 |     data: unsafe { &mut DATA },
      |     ^~~~
crab1: note: unify::go ltype={* mut ()} rtype={* mut DataType}
crab1: note: unify::go ltype={()} rtype={DataType}
/tmp/icemaker_global_tempdir.CmTzlVK6SkSa/rustc_testrunner_tmpdir_reporting.AVHRg2g2uLQ9/mvce.rs:6:5: error: mismatched types, expected ‘()’ but got ‘DataType’ [E0308]
    6 |     data: unsafe { &mut DATA },
      |     ^~~~                ~~~~
/tmp/icemaker_global_tempdir.CmTzlVK6SkSa/rustc_testrunner_tmpdir_reporting.AVHRg2g2uLQ9/mvce.rs:6:5: note: unify_site_and done ok=false commit true infer false id={49} expected={* mut ()} expr={* mut DataType}
crab1: note: coerce_default_unify(a={&mut DataType}, b={* mut ()})
/tmp/icemaker_global_tempdir.CmTzlVK6SkSa/rustc_testrunner_tmpdir_reporting.AVHRg2g2uLQ9/mvce.rs:6:5: note: begin unify_site_and commit true infer true check_bounds true id={50} expected={* mut ()} expr={&mut DataType}
    6 |     data: unsafe { &mut DATA },
      |     ^~~~
crab1: note: unify::go ltype={* mut ()} rtype={&mut DataType}
/tmp/icemaker_global_tempdir.CmTzlVK6SkSa/rustc_testrunner_tmpdir_reporting.AVHRg2g2uLQ9/mvce.rs:6:5: error: mismatched types, expected ‘* mut ()’ but got ‘&mut DataType’ [E0308]
    2 |     data: *mut (),
      |     ~~~~
......
    6 |     data: unsafe { &mut DATA },
      |     ^~~~  ~~~~~~
/tmp/icemaker_global_tempdir.CmTzlVK6SkSa/rustc_testrunner_tmpdir_reporting.AVHRg2g2uLQ9/mvce.rs:6:5: note: unify_site_and done ok=false commit true infer true id={50} expected={* mut ()} expr={&mut DataType}
crab1: internal compiler error: Segmentation fault
0x301f909 internal_error(char const*, ...)
	../../gcc/diagnostic-global-context.cc:786
0x199fb9f crash_signal
	../../gcc/toplev.cc:323
0xf3a720 Rust::Analysis::NodeMapping::get_nodeid() const
	../../gcc/rust/util/rust-hir-map.cc:48
0x101a551 Rust::Resolver::TypeCheckContext::insert_type(Rust::Analysis::NodeMapping const&, Rust::TyTy::BaseType*)
	../../gcc/rust/typecheck/rust-typecheck-context.cc:88
0x105d47a Rust::Resolver::TypeCheckStructExpr::resolve(Rust::HIR::StructExprStructFields&)
	../../gcc/rust/typecheck/rust-hir-type-check-struct.cc:131
0x105ee8f Rust::Resolver::TypeCheckStructExpr::Resolve(Rust::HIR::StructExprStructFields&)
	../../gcc/rust/typecheck/rust-hir-type-check-struct.cc:38
0x1064fab ???
	../../gcc/rust/typecheck/rust-hir-type-check-expr.h:61
0x1066284 Rust::Resolver::TypeCheckExpr::Resolve(Rust::HIR::Expr&)
	../../gcc/rust/typecheck/rust-hir-type-check-expr.cc:50
0x103a45c Rust::Resolver::TypeCheckItem::visit(Rust::HIR::StaticItem&)
	../../gcc/rust/typecheck/rust-hir-type-check-item.cc:432
0x103ac05 Rust::Resolver::TypeCheckItem::Resolve(Rust::HIR::Item&)
	../../gcc/rust/typecheck/rust-hir-type-check-item.cc:57
0xfda3bb Rust::Resolver::TypeResolution::Resolve(Rust::HIR::Crate&)
	../../gcc/rust/typecheck/rust-hir-type-check.cc:71
0xe875ec Rust::Session::compile_crate(char const*)
	../../gcc/rust/rust-session-manager.cc:682
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.

Contributor guide

Open the contributing guide

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.

Research direction

Reproduce the crash with the reduced Rust snippet using the reported crab1 command and compiler revision. Start by tracing NodeMapping::get_nodeid() during name resolution of the self-referential DATA initializer. Done means the reproducer no longer causes a segmentation fault and its reported diagnostics remain correct.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.