Rust-GCC / Rust-GCC/gccrs

ICE in get_function_expr, at rust/ast/rust-expr.h:2272 cfg'd return type from inside macro

Open
#4,167 1 comment 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-incomplete-and-experimental-compiler-do-not-use
macro_rules! the_macro {
    ( $foo:stmt ; $bar:stmt ; ) => {
        #[cfg(foo)]
        $foo

        $foo[cfg(bar)]
        $bar
    };
}

fn the_function() {
    the_macro!( (); (); );
}

original:

macro_rules! the_macro {
    ( $foo:stmt ; $bar:stmt ; ) => {
        #[cfg(foo)]
        $foo
        
        $foo[cfg(bar)]
        $bar
    };
}

fn the_function() {
    the_macro!( (); (); );
}

Version information:

4db0cf74f64086e2bb2eff029c597239df8442e1

Possibly related line of code:
https://github.com/Rust-GCC/gccrs/blob/4db0cf74f64086e2bb2eff029c597239df8442e1/gcc/rust/ast/rust-expr.h#L2266-L2278

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.DRLDZieGz8xT/mvce.rs:12:17: error: cannot strip expression in this position - outer attributes not allowed
   12 |     the_macro!( (); (); );
      |                 ^
/tmp/icemaker_global_tempdir.J4KdGj8QZ6tS/rustc_testrunner_tmpdir_reporting.DRLDZieGz8xT/mvce.rs:12:17: error: cannot strip expression in this position - outer attributes not allowed
crab1: internal compiler error: in get_function_expr, at rust/ast/rust-expr.h:2272
0x301e249 internal_error(char const*, ...)
	../../gcc/diagnostic-global-context.cc:786
0xc22881 fancy_abort(char const*, int, char const*)
	../../gcc/diagnostics/context.cc:1787
0x901db9 Rust::AST::CallExpr::get_function_expr()
	../../gcc/rust/ast/rust-expr.h:2272
0x901db9 Rust::AST::DefaultASTVisitor::visit(Rust::AST::CallExpr&)
	../../gcc/rust/ast/rust-ast-visitor.cc:417
0x901db9 Rust::AST::DefaultASTVisitor::visit(Rust::AST::CallExpr&)
	../../gcc/rust/ast/rust-ast-visitor.cc:414
0xe42d60 void Rust::AST::DefaultASTVisitor::visit<Rust::AST::Expr>(Rust::AST::Expr&)
	../../gcc/rust/ast/rust-ast-visitor.h:418
0xe42d60 Rust::AST::DefaultASTVisitor::visit(Rust::AST::ArrayIndexExpr&)
	../../gcc/rust/ast/rust-ast-visitor.cc:342
0xe42bce void Rust::AST::DefaultASTVisitor::visit<Rust::AST::Expr>(Rust::AST::Expr&)
	../../gcc/rust/ast/rust-ast-visitor.h:418
0xe42bce Rust::AST::DefaultASTVisitor::visit(Rust::AST::CallExpr&)
	../../gcc/rust/ast/rust-ast-visitor.cc:417
0xe4437f void Rust::AST::DefaultASTVisitor::visit<Rust::AST::Stmt>(std::unique_ptr<Rust::AST::Stmt, std::default_delete<Rust::AST::Stmt> >&)
	../../gcc/rust/ast/rust-ast-visitor.h:422
0xe4437f Rust::AST::DefaultASTVisitor::visit(Rust::AST::BlockExpr&)
	../../gcc/rust/ast/rust-ast-visitor.cc:458
0xf90129 std::function<void ()>::operator()() const
	/usr/include/c++/15.2.1/bits/std_function.h:593
0xf90129 Rust::Resolver2_0::NameResolutionContext::scoped(Rust::Resolver2_0::Rib::Kind, unsigned int, std::function<void ()>, tl::optional<Rust::Identifier>)
	../../gcc/rust/resolve/rust-name-resolution-context.cc:283
0xf94a3c Rust::Resolver2_0::DefaultResolver::visit(Rust::AST::BlockExpr&)
	../../gcc/rust/resolve/rust-default-resolver.cc:50
0xf992a9 operator()
	../../gcc/rust/resolve/rust-default-resolver.cc:72
0xf992a9 scope_inner<Rust::Resolver2_0::CanonicalPathCtx::scope<Rust::Resolver2_0::DefaultResolver::visit(Rust::AST::Function&)::<lambda()> >(Rust::NodeId, std::string, Rust::Resolver2_0::DefaultResolver::visit(Rust::AST::Function&)::<lambda()>&&)::<lambda()>, Rust::Resolver2_0::DefaultResolver::visit(Rust::AST::Function&)::<lambda()> >
	../../gcc/rust/resolve/rust-name-resolution-context.h:470
0xf992a9 scope<Rust::Resolver2_0::DefaultResolver::visit(Rust::AST::Function&)::<lambda()> >
	../../gcc/rust/resolve/rust-name-resolution-context.h:413
0xf992a9 scope<Rust::Resolver2_0::DefaultResolver::visit(Rust::AST::Function&)::<lambda()> >
	../../gcc/rust/resolve/rust-name-resolution-context.h:406
0xf992a9 operator()
	../../gcc/rust/resolve/rust-default-resolver.cc:75
0xf992a9 __invoke_impl<void, Rust::Resolver2_0::DefaultResolver::visit(Rust::AST::Function&)::<lambda()>&>
	/usr/include/c++/15.2.1/bits/invoke.h:63
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 ICE with the reduced Rust source and the shown compiler flag. Inspect rust/ast/rust-expr.h around CallExpr::get_function_expr and the related visitor path in rust-ast-visitor.cc. Done means this input no longer triggers an internal compiler error and the existing diagnostics remain intact.

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.