Skip to content

segfault in eval_component_reference #4157

@matthiaskrgr

Description

@matthiaskrgr

auto-reduced (treereduce-rust):

//@compile-flags: -frust-incomplete-and-experimental-compiler-do-not-use
struct MyStruct {}
struct Nested {
    nested: MyStruct,
}
struct Mix2 {
    nested: (Nested,),
}

const MIX_2: Mix2 = Mix2 { nested: ((2,),) };

fn main() {
    let f = [0; (MIX_2.nested.0).0];
}

original:

struct MyStruct { field: usize }
struct Nested { nested: MyStruct }
struct Mix2 { nested: (Nested,) }

const STRUCT: MyStruct = MyStruct { field: 42 };
const TUP: (usize,) = (43,);
const NESTED_S: Nested = Nested { nested: MyStruct { field: 5 } };
const NESTED_T: ((usize,),) = ((4,),);
const MIX_1: ((Nested,),) = ((MyStruct { field: 3 },),);
const MIX_2: Mix2 = Mix2 { nested: ((2,),) };
const INSTANT_1: usize = (MyStruct { field: 1 }).field;
const INSTANT_2: usize = (4,).0;

fn main() {
    let h = [0; STRUCT.field];
    let b = [0; TUP.0];
    let c = [0; NESTED_S.nested.field];
    let d = [0; (NESTED_T.0).0];
    let e = [0; (MIX_1.0).0.nested.field];
    let f = [0; (MIX_2.nested.0).0];
    let g = [0; INSTANT_1];
    let h = [0; INSTANT_2];
}

Version information:

4db0cf7

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

Program output

/tmp/icemaker_global_tempdir.J4KdGj8QZ6tS/rustc_testrunner_tmpdir_reporting.GTkQGoMLUyrX/mvce.rs:9:28: error: mismatched types, expected ‘Nested’ but got ‘(<integer>)’ [E0308]
    6 |     nested: (Nested,),
      |              ~~~~~~         
......
    9 | const MIX_2: Mix2 = Mix2 { nested: ((2,),) };
      |                            ^~~~~~   ~
/tmp/icemaker_global_tempdir.J4KdGj8QZ6tS/rustc_testrunner_tmpdir_reporting.GTkQGoMLUyrX/mvce.rs:12:13: error: mismatched types, expected ‘usize’ but got ‘MyStruct’ [E0308]
   12 |     let f = [0; (MIX_2.nested.0).0];
      |             ^   ~
crab1: sorry, unimplemented: constant folding not supported for this tree code
crab1: internal compiler error: Segmentation fault
0x301e249 internal_error(char const*, ...)
	../../gcc/diagnostic-global-context.cc:786
0x199e5df crash_signal
	../../gcc/toplev.cc:323
0x1151f43 eval_component_reference
	../../gcc/rust/backend/rust-constexpr.cc:1705
0x114e9cb eval_constant_expression
	../../gcc/rust/backend/rust-constexpr.cc:2335
0x1151f42 eval_component_reference
	../../gcc/rust/backend/rust-constexpr.cc:1703
0x114e9cb eval_constant_expression
	../../gcc/rust/backend/rust-constexpr.cc:2335
0x11538a8 eval_store_expression
	../../gcc/rust/backend/rust-constexpr.cc:2655
0x114cb52 eval_constant_expression
	../../gcc/rust/backend/rust-constexpr.cc:2176
0x114d8c1 eval_constant_expression
	../../gcc/rust/backend/rust-constexpr.cc:2104
0x114db5c eval_statement_list
	../../gcc/rust/backend/rust-constexpr.cc:4657
0x114db5c eval_constant_expression
	../../gcc/rust/backend/rust-constexpr.cc:2182
0x114cc95 eval_constant_expression
	../../gcc/rust/backend/rust-constexpr.cc:2186
0x114b924 eval_call_expression
	../../gcc/rust/backend/rust-constexpr.cc:3577
0x114cc5b eval_constant_expression
	../../gcc/rust/backend/rust-constexpr.cc:2099
0x114fbdc Rust::Compile::fold_expr(tree_node*)
	../../gcc/rust/backend/rust-constexpr.cc:565
0x115d1db Rust::Compile::HIRCompileBase::compile_constant_item(unsigned int, Rust::TyTy::BaseType*, Rust::TyTy::BaseType*, Rust::Resolver::CanonicalPath const&, Rust::HIR::Expr&, unsigned long, unsigned long)
	../../gcc/rust/backend/rust-compile-base.cc:886
0x115d784 Rust::Compile::HIRCompileBase::compile_constant_expr(Rust::Compile::Context*, unsigned int, Rust::TyTy::BaseType*, Rust::TyTy::BaseType*, Rust::Resolver::CanonicalPath const&, Rust::HIR::Expr&, unsigned long, unsigned long)
	../../gcc/rust/backend/rust-compile-base.cc:567
0x115d784 Rust::Compile::HIRCompileBase::query_compile_const_expr(Rust::Compile::Context*, Rust::TyTy::BaseType*, Rust::HIR::Expr&)
	../../gcc/rust/backend/rust-compile-base.cc:582
0x106df0d Rust::Resolver::TypeCheckExpr::visit(Rust::HIR::ArrayExpr&)
	../../gcc/rust/typecheck/rust-hir-type-check-expr.cc:1154
0x1065f44 Rust::Resolver::TypeCheckExpr::Resolve(Rust::HIR::Expr&)
	../../gcc/rust/typecheck/rust-hir-type-check-expr.cc:50
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.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions