Rust-GCC / Rust-GCC/gccrs

ICE in insert_metavar, at rust/expand/rust-macro-expand.h:225

Open
#3,587 0 comments 0 reactions 2 assignees View on GitHub

@P-E-P is already working on this.

Since Mar 28, 2025.

bug
Dominant language
C++
Stars
2.9k
Forks
231
Avg merge
19h 55m
Merged PRs (30d)
67

Description

auto-reduced (treereduce-rust):

macro_rules! m {
    ($b:tt $b:tt) => {
        $a $a;
    }
}

fn main() {
    m!(S struct);
}

original:

// check-pass

#![S(unused)]

macro_rules! m {
    ($b:tt $b:tt) => {
        $a $a; //~ WARN struct is never constructed
    }
}

fn main() {
    m!(S struct);
}

Version information:

34b0a681598d52de442a0a21c3a7df20bf1485bc

Possibly related line of code:
https://github.com/Rust-GCC/gccrs/blob/34b0a681598d52de442a0a21c3a7df20bf1485bc/gcc/rust/expand/rust-macro-expand.h#L219-L231

Command:
crab1 -Warray-bounds -mtune=generic -march=x86-64 -O0 -L/lib/x86_64-linux-gnu -L/lib/../lib64 -L/usr/lib/x86_64-linux-gnu -L/usr/lib/../lib64 -frust-incomplete-and-experimental-compiler-do-not-use

Program output

crab1: internal compiler error: in insert_metavar, at rust/expand/rust-macro-expand.h:225
0x86437f Rust::SubstitutionScope::insert_metavar(Rust::MatchedFragment)
	../../gcc/rust/expand/rust-macro-expand.h:225
0x86437f Rust::MacroExpander::match_matcher(Rust::Parser<Rust::MacroInvocLexer>&, Rust::AST::MacroMatcher&, bool, bool)
	../../gcc/rust/expand/rust-macro-expand.cc:517
0xc82272 Rust::MacroExpander::match_matcher(Rust::Parser<Rust::MacroInvocLexer>&, Rust::AST::MacroMatcher&, bool, bool)
	/usr/include/c++/14.2.1/bits/stl_construct.h:162
0xc82272 Rust::MacroExpander::try_match_rule(Rust::AST::MacroRule&, Rust::AST::DelimTokenTree&)
	../../gcc/rust/expand/rust-macro-expand.cc:376
0xc82473 Rust::MacroExpander::expand_decl_macro(unsigned int, Rust::AST::MacroInvocData&, Rust::AST::MacroRulesDefinition&, Rust::AST::InvocKind)
	../../gcc/rust/expand/rust-macro-expand.cc:90
0xc8328b Rust::MacroExpander::expand_invoc(Rust::AST::MacroInvocation&, Rust::AST::InvocKind)
	../../gcc/rust/expand/rust-macro-expand.cc:305
0xd3e9e0 void Rust::ExpandVisitor::expand_macro_children<std::vector<std::unique_ptr<Rust::AST::Stmt, std::default_delete<Rust::AST::Stmt> >, std::allocator<std::unique_ptr<Rust::AST::Stmt, std::default_delete<Rust::AST::Stmt> > > >, std::unique_ptr<Rust::AST::Stmt, std::default_delete<Rust::AST::Stmt> > >(std::vector<std::unique_ptr<Rust::AST::Stmt, std::default_delete<Rust::AST::Stmt> >, std::allocator<std::unique_ptr<Rust::AST::Stmt, std::default_delete<Rust::AST::Stmt> > > >&, std::function<std::unique_ptr<Rust::AST::Stmt, std::default_delete<Rust::AST::Stmt> > (Rust::AST::SingleASTNode)>)
	../../gcc/rust/expand/rust-expand-visitor.h:133
0xd3e9e0 Rust::ExpandVisitor::expand_inner_stmts(Rust::AST::BlockExpr&)
	../../gcc/rust/expand/rust-expand-visitor.cc:330
0xd3fbf0 Rust::ExpandVisitor::visit(Rust::AST::BlockExpr&)
	../../gcc/rust/expand/rust-expand-visitor.cc:629
0xd3db40 void Rust::ExpandVisitor::expand_macro_children<std::vector<std::unique_ptr<Rust::AST::Item, std::default_delete<Rust::AST::Item> >, std::allocator<std::unique_ptr<Rust::AST::Item, std::default_delete<Rust::AST::Item> > > >, std::unique_ptr<Rust::AST::Item, std::default_delete<Rust::AST::Item> > >(std::vector<std::unique_ptr<Rust::AST::Item, std::default_delete<Rust::AST::Item> >, std::allocator<std::unique_ptr<Rust::AST::Item, std::default_delete<Rust::AST::Item> > > >&, std::function<std::unique_ptr<Rust::AST::Item, std::default_delete<Rust::AST::Item> > (Rust::AST::SingleASTNode)>)
	../../gcc/rust/expand/rust-expand-visitor.h:133
0xd3db40 Rust::ExpandVisitor::expand_inner_items(std::vector<std::unique_ptr<Rust::AST::Item, std::default_delete<Rust::AST::Item> >, std::allocator<std::unique_ptr<Rust::AST::Item, std::default_delete<Rust::AST::Item> > > >&)
	../../gcc/rust/expand/rust-expand-visitor.cc:239
0xc46135 Rust::Session::expansion(Rust::AST::Crate&, Rust::Resolver2_0::NameResolutionContext&)
	../../gcc/rust/rust-session-manager.cc:959
0xc5bcd1 Rust::Session::compile_crate(char const*)
	../../gcc/rust/rust-session-manager.cc:619
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.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.