ICE in build2, at tree.cc, recursive const fn
Open
@philberty is already working on this.
Since Sep 3, 2026.
bug
const-generics
- Dominant language
- C++
- Stars
- 2.9k
- Forks
- 231
- Avg merge
- 19h 55m
- Merged PRs (30d)
- 67
Description
auto-reduced (treereduce-rust):
//@compile-flags: -frust-incomplete-and-experimental-compiler-do-not-use -frust-crate-attr=no_core
const fn add(x: usize, y: usize) -> usize {
add + y
}
const ARR: [i32; add(1, 2)] = [5, 6, 7];
original:
#![allow(dead_code)]
const fn add(x: usize, y: usize) -> usize {
add + y
}
const ARR: [i32; add(1, 2)] = [5, 6, 7];
pub fn main() {}
Version information:
206d052f0c25feb613d28fcd71877db7db089c14
Possibly related line of code:
https://github.com/Rust-GCC/gccrs/blob/206d052f0c25feb613d28fcd71877db7db089c14/gcc/tree.cc#L5280-L5292
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
/tmp/icemaker_global_tempdir.uWTdLfAKpi0h/rustc_testrunner_tmpdir_reporting.1gMqXB44gFBz/mvce.rs:2:5: error: cannot apply operator ‘+’ to types fn (x usize,y usize,) -> usize and usize
2 | add + y
| ^~~
crab1: internal compiler error: in build2, at tree.cc:5286
0x32c99c7 internal_error(char const*, ...)
../../gcc/diagnostic-global-context.cc:787
0xc7f8e1 fancy_abort(char const*, int, char const*)
../../gcc/diagnostics/context.cc:1813
0xacd1d3 build2(tree_code, tree_node*, tree_node*, tree_node*)
../../gcc/tree.cc:5286
0x14d3f91 build2_loc(unsigned long, tree_code, tree_node*, tree_node*, tree_node*)
../../gcc/tree.h:4950
0x14d3f91 fold_build2_loc(unsigned long, tree_code, tree_node*, tree_node*, tree_node*)
../../gcc/fold-const.cc:13616
0x14d3f6e fold_build2_loc(unsigned long, tree_code, tree_node*, tree_node*, tree_node*)
../../gcc/fold-const.cc:13614
0xd0a77d Backend::arithmetic_or_logical_expression(ArithmeticOrLogicalOperator, tree_node*, tree_node*, unsigned long)
../../gcc/rust/rust-gcc.cc:1115
0xd0a77d Backend::arithmetic_or_logical_expression(ArithmeticOrLogicalOperator, tree_node*, tree_node*, unsigned long)
../../gcc/rust/rust-gcc.cc:1076
0x11caeed Rust::Compile::CompileExpr::visit(Rust::HIR::ArithmeticOrLogicalExpr&)
../../gcc/rust/backend/rust-compile-expr.cc:304
0x11c1146 Rust::Compile::CompileExpr::Compile(Rust::HIR::Expr&, Rust::Compile::Context*)
../../gcc/rust/backend/rust-compile-expr.cc:164
0x11f1b73 Rust::Compile::HIRCompileBase::compile_function_body(tree_node*, Rust::HIR::BlockExpr&, Rust::TyTy::BaseType*)
../../gcc/rust/backend/rust-compile-base.cc:693
0x11f3473 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:886
0x11b41c6 Rust::Compile::CompileItem::visit(Rust::HIR::Function&)
../../gcc/rust/backend/rust-compile-item.cc:235
0xee9072 Rust::Compile::CompileItem::compile(Rust::HIR::Item*, Rust::Compile::Context*, Rust::TyTy::BaseType*, unsigned long)
../../gcc/rust/backend/rust-compile-item.h:37
0xee9072 Rust::Compile::HIRCompileBase::query_compile(unsigned int, Rust::TyTy::BaseType*, Rust::HIR::PathIdentSegment const&, Rust::Analysis::NodeMapping const&, unsigned long, bool)
../../gcc/rust/backend/rust-compile-resolve-path.cc:263
0xee9bc3 Rust::Compile::ResolvePathRef::resolve_with_node_id(Rust::HIR::PathIdentSegment const&, Rust::Analysis::NodeMapping const&, unsigned long, bool, unsigned int)
../../gcc/rust/backend/rust-compile-resolve-path.cc:215
0xeea411 Rust::Compile::ResolvePathRef::resolve(Rust::HIR::PathIdentSegment const&, Rust::Analysis::NodeMapping const&, unsigned long, bool)
../../gcc/rust/backend/rust-compile-resolve-path.cc:247
0xeea411 tree_node* Rust::Compile::ResolvePathRef::resolve_path_like<Rust::HIR::PathInExpression>(Rust::HIR::PathInExpression&)
../../gcc/rust/backend/rust-compile-resolve-path.cc:69
0xeea411 Rust::Compile::ResolvePathRef::Compile(Rust::HIR::PathInExpression&, Rust::Compile::Context*)
../../gcc/rust/backend/rust-compile-resolve-path.cc:47
0x11bbd3f ???
../../gcc/rust/backend/rust-compile-expr.h:62
/home/matthias/vcs/github/gccrs/gccrs-build/gcc/crab1 /tmp/icemaker_global_tempdir.uWTdLfAKpi0h/rustc_testrunner_tmpdir_reporting.1gMqXB44gFBz/mvce.rs -o/tmp/icemaker_global_tempdir.uWTdLfAKpi0h/rustc_testrunner_tmpdir_reporting.1gMqXB44gFBz/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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.