-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Don't lint against named labels in naked_asm!
#140871
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2874,14 +2874,28 @@ impl<'tcx> LateLintPass<'tcx> for AsmLabels { | |
if let hir::Expr { | ||
kind: | ||
hir::ExprKind::InlineAsm(hir::InlineAsm { | ||
asm_macro: AsmMacro::Asm | AsmMacro::NakedAsm, | ||
asm_macro: asm_macro @ (AsmMacro::Asm | AsmMacro::NakedAsm), | ||
template_strs, | ||
options, | ||
.. | ||
}), | ||
.. | ||
} = expr | ||
{ | ||
// Non-generic naked functions are allowed to define arbitrary | ||
// labels. | ||
if *asm_macro == AsmMacro::NakedAsm { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ... then with that def id, use
To avoid reinventing the wheel here. |
||
let mono = cx.generics.is_none_or(|generics| { | ||
generics | ||
.params | ||
.iter() | ||
.all(|param| matches!(param.kind, GenericParamKind::Lifetime { .. })) | ||
}); | ||
if mono { | ||
return; | ||
} | ||
} | ||
|
||
// asm with `options(raw)` does not do replacement with `{` and `}`. | ||
let raw = options.contains(InlineAsmOptions::RAW); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -171,12 +171,10 @@ fn main() { | |
} | ||
} | ||
|
||
// Trigger on naked fns too, even though they can't be inlined, reusing a | ||
// label or LTO can cause labels to break | ||
Comment on lines
-174
to
-175
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this not a valid concern? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think the original reasoning for closing #88169 was correct (even though it did come from me). Fundamentally there's no reason why you can't define global symbols in naked functions, the issue is only with local symbols ( In any case #128004 changed naked functions to use |
||
// Don't trigger on naked functions. | ||
#[unsafe(naked)] | ||
pub extern "C" fn foo() -> i32 { | ||
naked_asm!(".Lfoo: mov rax, {}; ret;", "nop", const 1) | ||
//~^ ERROR avoid using named labels | ||
} | ||
|
||
// Make sure that non-naked attributes *do* still let the lint happen | ||
|
@@ -190,7 +188,18 @@ pub extern "C" fn bar() { | |
pub extern "C" fn aaa() { | ||
fn _local() {} | ||
|
||
naked_asm!(".Laaa: nop; ret;") //~ ERROR avoid using named labels | ||
naked_asm!(".Laaa: nop; ret;") | ||
} | ||
|
||
#[unsafe(naked)] | ||
pub extern "C" fn bbb<'a>(a: &'a u32) { | ||
naked_asm!(".Lbbb: nop; ret;") | ||
} | ||
|
||
#[unsafe(naked)] | ||
pub extern "C" fn ccc<T>(a: &T) { | ||
naked_asm!(".Lccc: nop; ret;") | ||
//~^ ERROR avoid using named labels | ||
} | ||
|
||
pub fn normal() { | ||
|
@@ -200,7 +209,7 @@ pub fn normal() { | |
pub extern "C" fn bbb() { | ||
fn _very_local() {} | ||
|
||
naked_asm!(".Lbbb: nop; ret;") //~ ERROR avoid using named labels | ||
naked_asm!(".Lbbb: nop; ret;") | ||
} | ||
|
||
fn _local2() {} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Grab the def id here:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How exactly do I get a
DefId`` here? I only have a
HirIdsince this is a
LateLintPass` which runs on HIR.