segfault `Backend::is_floating_point` consts
Open
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-incomplete-and-experimental-compiler-do-not-use
fn main() {
const ARR: [i32; 6] = [42, 43, 44, 45, 46, 47];
const IDX: usize = 3;
const VAL: i32 = ARR[IDX];
const BLUB: [i32; (VAL[0] - 41) as usize] = [5];
}
original:
//@ build-pass (FIXME(62277): could be check-pass?)
fn main() {
const ARR: [i32; 6] = [42, 43, 44, 45, 46, 47];
const IDX: usize = 3;
const VAL: i32 = ARR[IDX];
const BLUB: [i32; (VAL[0] - 41) as usize] = [5];
}
Version information:
4db0cf74f64086e2bb2eff029c597239df8442e1
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.m0JdXA553lcj/mvce.rs:5:24: error: the type ‘i32’ cannot be indexed by ‘<integer>’ [E0277]
5 | const BLUB: [i32; (VAL[0] - 41) as usize] = [5];
| ^~~ ~
/tmp/icemaker_global_tempdir.J4KdGj8QZ6tS/rustc_testrunner_tmpdir_reporting.m0JdXA553lcj/mvce.rs:5:24: error: cannot apply operator ‘-’ to types <tyty::error> and <integer>
crab1: internal compiler error: Segmentation fault
0x301e249 internal_error(char const*, ...)
../../gcc/diagnostic-global-context.cc:786
0x199e5df crash_signal
../../gcc/toplev.cc:323
0xc9c35b Backend::is_floating_point(tree_node*)
../../gcc/rust/rust-gcc.cc:1019
0xc9c35b Backend::arithmetic_or_logical_expression(ArithmeticOrLogicalOperator, tree_node*, tree_node*, unsigned long)
../../gcc/rust/rust-gcc.cc:1075
0xc9c35b Backend::arithmetic_or_logical_expression(ArithmeticOrLogicalOperator, tree_node*, tree_node*, unsigned long)
../../gcc/rust/rust-gcc.cc:1059
0x113bc0d Rust::Compile::CompileExpr::visit(Rust::HIR::ArithmeticOrLogicalExpr&)
../../gcc/rust/backend/rust-compile-expr.cc:172
0x112f68a ???
../../gcc/rust/backend/rust-compile-expr.h:56
0x11373ba ???
../../gcc/rust/backend/rust-compile-expr.h:47
0x1133e16 Rust::Compile::CompileExpr::Compile(Rust::HIR::Expr&, Rust::Compile::Context*)
../../gcc/rust/backend/rust-compile-expr.cc:52
0x115d034 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:867
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
0x1052cb2 Rust::Resolver::TypeCheckType::visit(Rust::HIR::ArrayType&)
../../gcc/rust/typecheck/rust-hir-type-check-type.cc:729
0x104dc87 Rust::Resolver::TypeCheckType::Resolve(Rust::HIR::Type&)
../../gcc/rust/typecheck/rust-hir-type-check-type.cc:71
0x104ecc7 Rust::Resolver::TypeCheckType::Resolve(Rust::HIR::Type&)
../../gcc/rust/typecheck/rust-hir-type-check-type.cc:67
0x1075974 Rust::Resolver::TypeCheckStmt::visit(Rust::HIR::ConstantItem&)
../../gcc/rust/typecheck/rust-hir-type-check-stmt.cc:62
0x1076143 Rust::Resolver::TypeCheckStmt::Resolve(Rust::HIR::Stmt&)
../../gcc/rust/typecheck/rust-hir-type-check-stmt.cc:34
0x1067904 Rust::Resolver::TypeCheckExpr::visit(Rust::HIR::BlockExpr&)
../../gcc/rust/typecheck/rust-hir-type-check-expr.cc:614
0x1065f44 Rust::Resolver::TypeCheckExpr::Resolve(Rust::HIR::Expr&)
../../gcc/rust/typecheck/rust-hir-type-check-expr.cc:50
0x1043a36 Rust::Resolver::TypeCheckItem::visit(Rust::HIR::Function&)
../../gcc/rust/typecheck/rust-hir-type-check-item.cc:588
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.
Research direction
Reproduce the crash with the reduced Rust program and the listed compiler flag. Start in gcc/rust/rust-gcc.cc around Backend::is_floating_point and arithmetic_or_logical_expression, then trace the call from gcc/rust/backend/rust-compile-expr.cc. Done means the invalid constant expression reports its existing type errors without an internal compiler error or segmentation fault.
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
- Mostly clear
- Newbie friendliness
- 35/100