Rust-GCC / Rust-GCC/gccrs

segfault with attr on macro decl

Open
#4,479 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
#![no_core]

#[coverage(off)]

macro_rules! decl_foo {
    () => {
        static FOO: u32 = 0;
    };
}

decl_foo!();

original:

#![feature(no_core)]
#![no_core]
//@ ignore-lldb

// Test that static debug info is not collapsed with #[collapse_debuginfo(external)]

//@ compile-flags:-g
//@ ignore-backends: gcc

// === GDB TESTS ===================================================================================

//@ gdb-command:info line collapse_debuginfo_static_external::FOO
//@ gdb-check:[...]Line 16[...]

#[coverage(off)] //~ ERROR multiple `coverage` attributes
#[coverage(off)]
macro_rules! decl_foo {
    () => {
        static FOO: u32 = 0;
    };
}

decl_foo!();

fn main() {
    let mut res = Vec::new();
    let s1 = vec![1, 2, 3, 4];
    res.extend_from_slice(&s1);
    res.extend_from_slice(&s1);
    res.extend_from_slice(&s1);
    res.extend_from_slice(&s1);
    res
}

Version information:

1a9102843099b18f9dbb6b5e979436f6c4566f1c

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

Program output

/tmp/icemaker_global_tempdir.BuEqbgOPwAlh/rustc_testrunner_tmpdir_reporting.VYvgZlGkeT2Q/mvce.rs:3:3: error: macro not found
    3 | #[coverage(off)]
      |   ^~~~~~~~
crab1: internal compiler error: Segmentation fault
0x3097ef9 internal_error(char const*, ...)
	../../gcc/diagnostic-global-context.cc:787
0x19c085f crash_signal
	../../gcc/toplev.cc:325
0xe98330 Rust::MacroExpander::expand_decl_macro(unsigned long, Rust::AST::MacroInvocData&, Rust::AST::MacroRulesDefinition&, Rust::AST::InvocKind)
	../../gcc/rust/expand/rust-macro-expand.cc:43
0xe991eb Rust::MacroExpander::expand_invoc(Rust::AST::MacroInvocation&, Rust::AST::InvocKind)
	../../gcc/rust/expand/rust-macro-expand.cc:333
0xea7f5a 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::unique_ptr<Rust::AST::Item, std::default_delete<Rust::AST::Item> > (Rust::AST::SingleASTNode::*)())
	../../gcc/rust/expand/rust-expand-visitor.h:154
0xea7f5a 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:243
0xe65cdb Rust::Session::expansion(Rust::AST::Crate&, Rust::Resolver2_0::NameResolutionContext&)
	../../gcc/rust/rust-session-manager.cc:1039
0xe73f9b Rust::Session::compile_crate(char const*)
	../../gcc/rust/rust-session-manager.cc:698
/home/matthias/vcs/github/gccrs/gccrs-build/gcc/crab1 /tmp/icemaker_global_tempdir.BuEqbgOPwAlh/rustc_testrunner_tmpdir_reporting.VYvgZlGkeT2Q/mvce.rs -o/tmp/icemaker_global_tempdir.BuEqbgOPwAlh/rustc_testrunner_tmpdir_reporting.VYvgZlGkeT2Q/binaryname -frust-incomplete-and-experimental-compiler-do-not-use
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

Start with gcc/rust/expand/rust-macro-expand.cc at Rust::MacroExpander::expand_decl_macro, identified by the backtrace, and reproduce the crash with the reduced /tmp/im/a.rs case and its compile flag. Done means the #[coverage(off)] macro declaration produces a diagnostic or continues without a segmentation fault.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, rust
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.