Rust-GCC / Rust-GCC/gccrs

AST: segfault with garbage cfg attr

Open
#4,147 0 comments 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
#[cfg(|_: fn() -> B| C | D)]
mod foo {}

original:

// Expansion drives parsing, so conditional compilation will strip
// out outline modules and we will never attempt parsing them.

//@ check-pass

fn main() {}

#[cfg(|_: fn() -> B| C | D)]
mod foo {
    mod bar {
        mod baz; // This was an error before.
    }
}

Version information:

c742973c23448e321fba4d9ff98a9092dc0df7ba

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

Program output

/tmp/icemaker_global_tempdir.4jbydGKfmYZn/rustc_testrunner_tmpdir_reporting.8IbjznFHEQef/mvce.rs:1:7: error: unrecognised token '|' in meta item
    1 | #[cfg(|_: fn() -> B| C | D)]
      |       ^
/tmp/icemaker_global_tempdir.4jbydGKfmYZn/rustc_testrunner_tmpdir_reporting.8IbjznFHEQef/mvce.rs:1:7: error: failed to parse inner meta item in attribute
crab1: internal compiler error: Segmentation fault
0x300c7d8 internal_error(char const*, ...)
	../../gcc/diagnostic-global-context.cc:534
0x199d0df crash_signal
	../../gcc/toplev.cc:323
0xdf23c1 std::__uniq_ptr_impl<Rust::AST::MetaItemInner, std::default_delete<Rust::AST::MetaItemInner> >::_M_ptr() const
	/usr/include/c++/15.2.1/bits/unique_ptr.h:193
0xdf23c1 std::unique_ptr<Rust::AST::MetaItemInner, std::default_delete<Rust::AST::MetaItemInner> >::get() const
	/usr/include/c++/15.2.1/bits/unique_ptr.h:473
0xdf23c1 std::unique_ptr<Rust::AST::MetaItemInner, std::default_delete<Rust::AST::MetaItemInner> >::operator->() const
	/usr/include/c++/15.2.1/bits/unique_ptr.h:466
0xdf23c1 Rust::AST::Attribute::check_cfg_predicate(Rust::Session const&) const
	../../gcc/rust/ast/rust-ast.cc:4196
0xead14e Rust::CfgStrip::fails_cfg_with_expand(std::vector<Rust::AST::Attribute, std::allocator<Rust::AST::Attribute> >&) const
	../../gcc/rust/expand/rust-cfg-strip.cc:75
0xeaf41b Rust::CfgStrip::visit(Rust::AST::Module&)
	../../gcc/rust/expand/rust-cfg-strip.cc:1769
0xe4262f void Rust::AST::DefaultASTVisitor::visit<Rust::AST::Item>(std::unique_ptr<Rust::AST::Item, std::default_delete<Rust::AST::Item> >&)
	../../gcc/rust/ast/rust-ast-visitor.h:422
0xe4262f Rust::AST::DefaultASTVisitor::visit(Rust::AST::Crate&)
	../../gcc/rust/ast/rust-ast-visitor.cc:39
0xeafc39 Rust::CfgStrip::visit(Rust::AST::Crate&)
	../../gcc/rust/expand/rust-cfg-strip.cc:165
0xe7aed8 Rust::Session::expansion(Rust::AST::Crate&, Rust::Resolver2_0::NameResolutionContext&)
	../../gcc/rust/rust-session-manager.cc:943
0xe87f25 Rust::Session::compile_crate(char const*)
	../../gcc/rust/rust-session-manager.cc:618
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 crash with the reduced Rust input and command shown in the issue. Start at Rust::AST::Attribute::check_cfg_predicate in gcc/rust/ast/rust-ast.cc:4196, then follow the cfg-strip callers in gcc/rust/expand/rust-cfg-strip.cc. Done means the malformed cfg attribute still reports its parse errors without causing a 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
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.