Skip to content

ICE: in struct_field_expression, at rust/rust-gcc.cc:884 #3672

Open
@matthiaskrgr

Description

@matthiaskrgr

auto-reduced (treereduce-rust):

//@compile-flags: -frust-incomplete-and-experimental-compiler-do-not-use
struct Y(usize, usize);

fn distinct_variant() {
    let mut y = Y(1, 2);

    let a = match y {
        Y(ref mut a, _) => a,
    };

    let b = match y {
        Y(_, ref mut b) => b,
    };

    *a += 1;
    *b += 1;
}

original:

// Tests that we are able to distinguish when loans borrow different
// anonymous fields of a tuple vs the same anonymous field.

struct Y(usize, usize);

fn distinct_variant() {
    let mut y = Y(1, 2);

    let a = match y {
        Y(ref mut a, _) => a
    };

    let b = match y {
        Y(_, ref mut b) => b
    };

    *a += 1;
    *b += 1;
}

fn same_variant() {
    let mut y = Y(1, 2);

    let a = match y {
        Y(ref mut a, _) => a
    };

    let b = match y {
        Y(_, ref mut b) => b
    };

    *a += 1;
    *b += 1;
}

fn main() {
}

Version information:

7651217

Possibly related line of code:

gccrs/gcc/rust/rust-gcc.cc

Lines 878 to 890 in 7651217

tree
struct_field_expression (tree struct_tree, size_t index, location_t location)
{
if (struct_tree == error_mark_node
|| TREE_TYPE (struct_tree) == error_mark_node)
return error_mark_node;
gcc_assert (TREE_CODE (TREE_TYPE (struct_tree)) == RECORD_TYPE
|| TREE_CODE (TREE_TYPE (struct_tree)) == UNION_TYPE);
tree field = TYPE_FIELDS (TREE_TYPE (struct_tree));
if (field == NULL_TREE)
{
// This can happen for a type which refers to itself indirectly
// and then turns out to be erroneous.

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

Program output

crab1: internal compiler error: in struct_field_expression, at rust/rust-gcc.cc:884
0x885c57 Backend::struct_field_expression(tree_node*, unsigned long, unsigned int)
	../../gcc/rust/rust-gcc.cc:884
0x105f59e Rust::Compile::CompilePatternCheckExpr::visit(Rust::HIR::TupleStructPattern&)
	../../gcc/rust/backend/rust-compile-pattern.cc:363
0x1079941 Rust::Compile::CompilePatternCheckExpr::Compile(Rust::HIR::Pattern&, tree_node*, Rust::Compile::Context*)
	../../gcc/rust/backend/rust-compile-pattern.h:33
0x1079941 Rust::Compile::CompileExpr::visit(Rust::HIR::MatchExpr&)
	../../gcc/rust/backend/rust-compile-expr.cc:1180
0x1071b40 Rust::Compile::CompileExpr::Compile(Rust::HIR::Expr&, Rust::Compile::Context*)
	../../gcc/rust/backend/rust-compile-expr.cc:47
0x106ca71 Rust::Compile::CompileStmt::visit(Rust::HIR::LetStmt&)
	../../gcc/rust/backend/rust-compile-stmt.cc:71
0x106cc8d Rust::Compile::CompileStmt::Compile(Rust::HIR::Stmt*, Rust::Compile::Context*)
	../../gcc/rust/backend/rust-compile-stmt.cc:36
0x109e6db Rust::Compile::HIRCompileBase::compile_function_body(tree_node*, Rust::HIR::BlockExpr&, Rust::TyTy::BaseType*)
	../../gcc/rust/backend/rust-compile-base.cc:591
0x10a226c Rust::Compile::HIRCompileBase::compile_function(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, 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 int, Rust::HIR::BlockExpr*, Rust::Resolver::CanonicalPath const&, Rust::TyTy::FnType*)
	../../gcc/rust/backend/rust-compile-base.cc:773
0x1068b2d Rust::Compile::CompileItem::visit(Rust::HIR::Function&)
	../../gcc/rust/backend/rust-compile-item.cc:256
0xcf15f4 Rust::Compile::CompileItem::compile(Rust::HIR::Item*, Rust::Compile::Context*, Rust::TyTy::BaseType*, unsigned int)
	../../gcc/rust/backend/rust-compile-item.h:37
0xcf15f4 Rust::Compile::CompileCrate::go()
	../../gcc/rust/backend/rust-compile.cc:48
0xcf16db Rust::Compile::CompileCrate::Compile(Rust::HIR::Crate&, Rust::Compile::Context*)
	../../gcc/rust/backend/rust-compile.cc:41
0xce90eb Rust::Session::compile_crate(char const*)
	../../gcc/rust/rust-session-manager.cc:733
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

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions