Skip to content

Commit 6541903

Browse files
committed
Don't lint against named labels in naked_asm!
Naked functions are allowed to define global labels, just like `global_asm!`.
1 parent dcecb99 commit 6541903

File tree

3 files changed

+9
-38
lines changed

3 files changed

+9
-38
lines changed

compiler/rustc_lint/src/builtin.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2909,7 +2909,7 @@ impl<'tcx> LateLintPass<'tcx> for AsmLabels {
29092909
if let hir::Expr {
29102910
kind:
29112911
hir::ExprKind::InlineAsm(hir::InlineAsm {
2912-
asm_macro: AsmMacro::Asm | AsmMacro::NakedAsm,
2912+
asm_macro: AsmMacro::Asm,
29132913
template_strs,
29142914
options,
29152915
..

tests/ui/asm/named-asm-labels.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -171,12 +171,10 @@ fn main() {
171171
}
172172
}
173173

174-
// Trigger on naked fns too, even though they can't be inlined, reusing a
175-
// label or LTO can cause labels to break
174+
// Don't trigger on naked functions.
176175
#[unsafe(naked)]
177176
pub extern "C" fn foo() -> i32 {
178177
naked_asm!(".Lfoo: mov rax, {}; ret;", "nop", const 1)
179-
//~^ ERROR avoid using named labels
180178
}
181179

182180
// Make sure that non-naked attributes *do* still let the lint happen
@@ -190,7 +188,7 @@ pub extern "C" fn bar() {
190188
pub extern "C" fn aaa() {
191189
fn _local() {}
192190

193-
naked_asm!(".Laaa: nop; ret;") //~ ERROR avoid using named labels
191+
naked_asm!(".Laaa: nop; ret;")
194192
}
195193

196194
pub fn normal() {
@@ -200,7 +198,7 @@ pub fn normal() {
200198
pub extern "C" fn bbb() {
201199
fn _very_local() {}
202200

203-
naked_asm!(".Lbbb: nop; ret;") //~ ERROR avoid using named labels
201+
naked_asm!(".Lbbb: nop; ret;")
204202
}
205203

206204
fn _local2() {}

tests/ui/asm/named-asm-labels.stderr

Lines changed: 5 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -475,16 +475,7 @@ LL | #[warn(named_asm_labels)]
475475
| ^^^^^^^^^^^^^^^^
476476

477477
error: avoid using named labels in inline assembly
478-
--> $DIR/named-asm-labels.rs:178:17
479-
|
480-
LL | naked_asm!(".Lfoo: mov rax, {}; ret;", "nop", const 1)
481-
| ^^^^^
482-
|
483-
= help: only local labels of the form `<number>:` should be used in inline asm
484-
= note: see the asm section of Rust By Example <https://doc.rust-lang.org/nightly/rust-by-example/unsafe/asm.html#labels> for more information
485-
486-
error: avoid using named labels in inline assembly
487-
--> $DIR/named-asm-labels.rs:185:20
478+
--> $DIR/named-asm-labels.rs:183:20
488479
|
489480
LL | unsafe { asm!(".Lbar: mov rax, {}; ret;", "nop", const 1, options(noreturn)) }
490481
| ^^^^^
@@ -493,25 +484,7 @@ LL | unsafe { asm!(".Lbar: mov rax, {}; ret;", "nop", const 1, options(noret
493484
= note: see the asm section of Rust By Example <https://doc.rust-lang.org/nightly/rust-by-example/unsafe/asm.html#labels> for more information
494485

495486
error: avoid using named labels in inline assembly
496-
--> $DIR/named-asm-labels.rs:193:17
497-
|
498-
LL | naked_asm!(".Laaa: nop; ret;")
499-
| ^^^^^
500-
|
501-
= help: only local labels of the form `<number>:` should be used in inline asm
502-
= note: see the asm section of Rust By Example <https://doc.rust-lang.org/nightly/rust-by-example/unsafe/asm.html#labels> for more information
503-
504-
error: avoid using named labels in inline assembly
505-
--> $DIR/named-asm-labels.rs:203:21
506-
|
507-
LL | naked_asm!(".Lbbb: nop; ret;")
508-
| ^^^^^
509-
|
510-
= help: only local labels of the form `<number>:` should be used in inline asm
511-
= note: see the asm section of Rust By Example <https://doc.rust-lang.org/nightly/rust-by-example/unsafe/asm.html#labels> for more information
512-
513-
error: avoid using named labels in inline assembly
514-
--> $DIR/named-asm-labels.rs:212:15
487+
--> $DIR/named-asm-labels.rs:210:15
515488
|
516489
LL | asm!("closure1: nop");
517490
| ^^^^^^^^
@@ -520,7 +493,7 @@ LL | asm!("closure1: nop");
520493
= note: see the asm section of Rust By Example <https://doc.rust-lang.org/nightly/rust-by-example/unsafe/asm.html#labels> for more information
521494

522495
error: avoid using named labels in inline assembly
523-
--> $DIR/named-asm-labels.rs:216:15
496+
--> $DIR/named-asm-labels.rs:214:15
524497
|
525498
LL | asm!("closure2: nop");
526499
| ^^^^^^^^
@@ -529,13 +502,13 @@ LL | asm!("closure2: nop");
529502
= note: see the asm section of Rust By Example <https://doc.rust-lang.org/nightly/rust-by-example/unsafe/asm.html#labels> for more information
530503

531504
error: avoid using named labels in inline assembly
532-
--> $DIR/named-asm-labels.rs:226:19
505+
--> $DIR/named-asm-labels.rs:224:19
533506
|
534507
LL | asm!("closure3: nop");
535508
| ^^^^^^^^
536509
|
537510
= help: only local labels of the form `<number>:` should be used in inline asm
538511
= note: see the asm section of Rust By Example <https://doc.rust-lang.org/nightly/rust-by-example/unsafe/asm.html#labels> for more information
539512

540-
error: aborting due to 56 previous errors; 1 warning emitted
513+
error: aborting due to 53 previous errors; 1 warning emitted
541514

0 commit comments

Comments
 (0)