Skip to content

fix ICE in #[naked] attribute validation #140193

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion compiler/rustc_passes/src/check_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -680,10 +680,14 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
}

if !other_attr.has_any_name(ALLOW_LIST) {
let path = other_attr.path();
let path: Vec<_> = path.iter().map(|s| s.as_str()).collect();
let other_attr_name = path.join("::");

self.dcx().emit_err(errors::NakedFunctionIncompatibleAttribute {
span: other_attr.span(),
naked_span: attr.span(),
attr: other_attr.name().unwrap(),
attr: other_attr_name,
});

return;
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_passes/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1249,7 +1249,7 @@ pub(crate) struct NakedFunctionIncompatibleAttribute {
pub span: Span,
#[label(passes_naked_attribute)]
pub naked_span: Span,
pub attr: Symbol,
pub attr: String,
}

#[derive(Diagnostic)]
Expand Down
9 changes: 9 additions & 0 deletions tests/ui/asm/naked-invalid-attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,12 @@ fn main() {
#[unsafe(naked)] //~ ERROR should be applied to a function definition
|| {};
}

// Check that the path of an attribute without a name is printed correctly (issue #140082)
#[::a]
//~^ ERROR attribute incompatible with `#[unsafe(naked)]`
//~| ERROR failed to resolve: use of unresolved module or unlinked crate `a`
#[unsafe(naked)]
extern "C" fn issue_140082() {
naked_asm!("")
}
19 changes: 18 additions & 1 deletion tests/ui/asm/naked-invalid-attr.stderr
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
error[E0433]: failed to resolve: use of unresolved module or unlinked crate `a`
--> $DIR/naked-invalid-attr.rs:56:5
|
LL | #[::a]
| ^ use of unresolved module or unlinked crate `a`

error: attribute should be applied to a function definition
--> $DIR/naked-invalid-attr.rs:13:1
|
Expand Down Expand Up @@ -27,6 +33,15 @@ LL | #[unsafe(naked)]
LL | || {};
| ----- not a function definition

error[E0736]: attribute incompatible with `#[unsafe(naked)]`
--> $DIR/naked-invalid-attr.rs:56:1
|
LL | #[::a]
| ^^^^^^ the `{{root}}::a` attribute is incompatible with `#[unsafe(naked)]`
...
LL | #[unsafe(naked)]
| ---------------- function marked with `#[unsafe(naked)]` here

error: attribute should be applied to a function definition
--> $DIR/naked-invalid-attr.rs:22:5
|
Expand All @@ -49,5 +64,7 @@ error: attribute should be applied to a function definition
LL | #![unsafe(naked)]
| ^^^^^^^^^^^^^^^^^ cannot be applied to crates

error: aborting due to 6 previous errors
error: aborting due to 8 previous errors

Some errors have detailed explanations: E0433, E0736.
For more information about an error, try `rustc --explain E0433`.
Loading