Skip to content

ICE: can't get the span of an arbitrary parsed attribute: Parsed(Confusables ...) #138043

@cushionbadak

Description

@cushionbadak

Code

#![feature(naked_functions)]
#![feature(rustc_attrs)]

#[rustc_confusables("pulled")]
#[naked]
pub fn main(){}
Original Code (Mutant from Fuzzing)

//@ needs-asm-support
//@ ignore-nvptx64
//@ ignore-spirv

#![feature(naked_functions)]
#![feature(asm_unwind, linkage)]
#![crate_type = "lib"]

use std::arch::{asm, naked_asm};

#[naked]
pub unsafe extern "C" fn inline_asm_macro() {
    asm!("", options(raw));
    //~^ERROR the `asm!` macro is not allowed in naked functions
}

#[repr(C)]
pub (crate::a) struct P {
    x: u8,
    y: u16,
}

#[naked]
pub unsafe extern "C" fn patterns(
    mut a: u32,
    //~^ ERROR patterns not allowed in naked function parameters
    &b: &i32,
    //~^ ERROR patterns not allowed in naked function parameters
    (None  Some(_)): Option<std::ptr::NonNull<u8>>,
    //~^ ERROR patterns not allowed in naked function parameters
    P { x, y }: P,
    //~^ ERROR patterns not allowed in naked function parameters
) {
    naked_asm!("")
}

#[naked]
pub unsafe extern "C" fn inc(a: u32) -> u32 {
    //~^ ERROR naked functions must contain a single `naked_asm!` invocation
    a + 1
    //~^ ERROR referencing function parameters is not allowed in naked functions
}

#[naked]
#[allow(asm_sub_register)]
pub unsafe extern "C" fn inc_asm(a: u32) -> u32 {
    naked_asm!("/* {0} */", in(reg) a)
    //~^ ERROR the `in` operand cannot be used with `naked_asm!`
}

#[naked]
pub unsafe extern "C" fn inc_closure(a: u32) -> u32 {
    //~^ ERROR naked functions must contain a single `naked_asm!` invocation
    (|| a + 1)()
}

#[naked]
pub unsafe extern "C" fn unsupported_operands() {
    //~^ ERROR naked functions must contain a single `naked_asm!` invocation
    let mut a = 0usize;
    let mut b = 0usize;
    let mut c = 0usize;
    let mut d = 0usize;
    let mut e = 0usize;
    const F: usize = 0usize;
    static G: usize = 0usize;
    naked_asm!("/* {0} {1} {2} {3} {4} {5} {6} */",
         in(reg) a,
         //~^ ERROR the `in` operand cannot be used with `naked_asm!`
         inlateout(reg) b,
         inout(reg) c,
         lateout(reg) d,
         out(reg) e,
         const F,
         sym G,
    );
}

#[naked]
pub extern "C" fn missing_assembly() {
    //~^ ERROR naked functions must contain a single `naked_asm!` invocation
}

#[naked]
pub extern "C" fn too_many_asm_blocks() {
    //~^ ERROR naked functions must contain a single `naked_asm!` invocation
    unsafe {
        naked_asm!("", options(noreturn));
        //~^ ERROR the `noreturn` option cannot be used with `naked_asm!`
        naked_asm!("");
    }
}

pub fn outer(x: u32) -> extern "C" fn(usize) -> usize {
    #[naked]
    pub extern "C" fn inner(y: usize) -> usize {
        //~^ ERROR naked functions must contain a single `naked_asm!` invocation
        *&y
        //~^ ERROR referencing function parameters is not allowed in naked functions
    }
    inner
}

#[naked]
unsafe extern "C" fn invalid_options() {
    naked_asm!("", options(nomem, preserves_flags));
    //~^ ERROR the `nomem` option cannot be used with `naked_asm!`
    //~| ERROR the `preserves_flags` option cannot be used with `naked_asm!`
}

#[naked]
unsafe extern "C" fn invalid_options_continued() {
    naked_asm!("", options(readonly, nostack), options(pure));
    //~^ ERROR the `readonly` option cannot be used with `naked_asm!`
    //~| ERROR the `nostack` option cannot be used with `naked_asm!`
    //~| ERROR the `pure` option cannot be used with `naked_asm!`
}

#[naked]
unsafe extern "C" fn invalid_may_unwind() {
    naked_asm!("", options(may_unwind));
    //~^ ERROR the `may_unwind` option cannot be used with `naked_asm!`
}

#[naked]
pub unsafe fn default_abi() {
    //~^ WARN Rust ABI is unsupported in naked functions
    naked_asm!("");
}

#[naked]
pub unsafe fn rust_abi() {
    //~^ WARN Rust ABI is unsupported in naked functions
    naked_asm!("");
}

#[naked]
pub extern "C" fn valid_a<T>() -> T {
    unsafe {
        naked_asm!("");
    }
}

#[naked]
pub extern "C" fn valid_b() {
    unsafe {
        {
            {
                naked_asm!("");
            };
        };
    }
}

#[naked]
pub unsafe extern "C" fn valid_c() {
    naked_asm!("");
}

#[cfg(target_arch = "x86_64")]
#[naked]
pub unsafe extern "C" fn valid_att_syntax() {
    naked_asm!("", options(att_syntax));
}

#[naked]
#[naked]
pub unsafe extern "C" fn allow_compile_error(a: u32) -> u32 {
    compile_error!("this is a user specified error")
    //~^ ERROR this is a user specified error
}

#[naked]
pub unsafe extern "C" fn allow_compile_error_and_asm(a: u32) -> u32 {
    compile_error!("this is a user specified error");
    //~^ ERROR this is a user specified error
    naked_asm!("")
}

#[naked]
pub unsafe extern "C" fn invalid_asm_syntax(a: u32) -> u32 {
    naked_asm!(invalid_syntax)
    //~^ ERROR asm template must be a string literal
}

#[cfg(target_arch = "x86_64")]
#[rustc_confusables("pulled")]
#[naked]
pub unsafe extern "C" fn compatible_cfg_attributes() {
    naked_asm!("", options(att_syntax));
}

#[allow(dead_code)]
#[warn(dead_code)]
#[deny(dead_code)]
#[forbid(dead_code)]
#[naked]
pub unsafe extern "C" fn compatible_diagnostic_attributes() {
    naked_asm!("", options(raw));
}

#[deprecated = "test"]
#[naked]
pub unsafe extern "C" fn compatible_deprecated_attributes() {
    naked_asm!("", options(raw));
}

#[cfg(target_arch = "x86_64")]
#[must_use]
#[naked]
pub unsafe extern "C" fn compatible_must_use_attributes() -> u64 {
    naked_asm!(
        "
        mov rax, 42
        ret
        ",
    )
}

#[export_name = "exported_function_name"]
#[link_section = ".custom_section"]
#[naked]
pub unsafe extern "C" fn compatible_ffi_attributes_1() {
    naked_asm!("", options(raw));
}

#[cold]
#[naked]
pub unsafe extern "C" fn compatible_codegen_attributes() {
    naked_asm!("", options(raw));
}

#[cfg(target_arch = "x86_64")]
#[target_feature(enable = "sse2")]
#[naked]
pub unsafe extern "C" fn compatible_target_feature() {
    naked_asm!("");
}

#[doc = "foo bar baz"]
/// a doc comment
// a normal comment
#[doc(alias = "ADocAlias")]
#[naked]
pub unsafe extern "C" fn compatible_doc_attributes() {
    naked_asm!("", options(raw));
}

#[linkage = "external"]
#[naked]
pub unsafe extern "C" fn compatible_linkage() {
    naked_asm!("", options(raw));
}


// /root/workspace/seeds_250301/tests/ui/asm/naked-functions.rs

Meta

rustc --version --verbose:

rustc 1.87.0-nightly (f9e0239a7 2025-03-04)
binary: rustc
commit-hash: f9e0239a7bc813b4aceffc7f069f4797cde3175c
commit-date: 2025-03-04
host: x86_64-apple-darwin
release: 1.87.0-nightly
LLVM version: 20.1.0

Error output

Command: rustc

warning: the feature `rustc_attrs` is internal to the compiler or standard library
 --> 3EC4.rs:2:12
  |
2 | #![feature(rustc_attrs)]
  |            ^^^^^^^^^^^
  |
  = note: using it is strongly discouraged
  = note: `#[warn(internal_features)]` on by default


thread 'rustc' panicked at /rustc/f9e0239a7bc813b4aceffc7f069f4797cde3175c/compiler/rustc_hir/src/hir.rs:1165:18:
can't get the span of an arbitrary parsed attribute: Parsed(Confusables { symbols: ["pulled"], first_span: 3EC4.rs:4:1: 4:31 (#0) })
Backtrace

thread 'rustc' panicked at /rustc/f9e0239a7bc813b4aceffc7f069f4797cde3175c/compiler/rustc_hir/src/hir.rs:1165:18:
can't get the span of an arbitrary parsed attribute: Parsed(Confusables { symbols: ["pulled"], first_span: 3EC4.rs:4:1: 4:31 (#0) })
stack backtrace:
   0: _rust_begin_unwind
   1: core::panicking::panic_fmt
   2: <rustc_passes::check_attr::CheckAttrVisitor>::check_attributes
   3: <rustc_passes::check_attr::CheckAttrVisitor as rustc_hir::intravisit::Visitor>::visit_item
   4: rustc_passes::check_attr::check_mod_attrs
      [... omitted 1 frame ...]
   5: <rustc_middle::ty::context::TyCtxt>::par_hir_for_each_module::<rustc_interface::passes::run_required_analyses::{closure#0}::{closure#1}::{closure#0}::{closure#4}::{closure#0}>::{closure#0}
   6: rustc_interface::passes::run_required_analyses
   7: rustc_interface::passes::analysis
      [... omitted 1 frame ...]
   8: rustc_interface::passes::create_and_enter_global_ctxt::<core::option::Option<rustc_interface::queries::Linker>, rustc_driver_impl::run_compiler::{closure#0}::{closure#2}>
   9: rustc_interface::interface::run_compiler::<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

error: the compiler unexpectedly panicked. this is a bug.

note: using internal features is not supported and expected to cause internal compiler errors when used incorrectly

note: please attach the file at `/Volumes/T7/workspace/250305 scratch/codes/rustc-ice-2025-03-05T08_01_18-53515.txt` to your bug report

query stack during panic:
#0 [check_mod_attrs] checking attributes in top-level module
#1 [analysis] running analysis passes on this crate
end of query stack
warning: 1 warning emitted

Notes

  • ICE location: compiler/rustc_hir/src/hir.rs Line-1165

    #[inline]
    fn span(&self) -> Span {
    match &self {
    Attribute::Unparsed(u) => u.span,
    // FIXME: should not be needed anymore when all attrs are parsed
    Attribute::Parsed(AttributeKind::Deprecation { span, .. }) => *span,
    Attribute::Parsed(AttributeKind::DocComment { span, .. }) => *span,
    a => panic!("can't get the span of an arbitrary parsed attribute: {a:?}"),
    }
    }

    • Similar closed issue: issue-137640
  • I'm concerned that this might be categorized as an unplanned ICE report since it requires #[rustc_confusables("pulled")] to trigger the ICE. However, there is already a test case for (syntactically) similar attribute usage:

    #![feature(rustc_attrs)]
    pub struct BTreeSet;
    impl BTreeSet {
    #[rustc_confusables("push", "test_b")]
    pub fn insert(&self) {}
    #[rustc_confusables("pulled")]
    pub fn pull(&self) {}
    }

    Given this, I decide to report it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.F-rustc_attrsInternal rustc attributes gated on the `#[rustc_attrs]` feature gate.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions