Skip to content

Commit

Permalink
Rollup merge of #99192 - Amanieu:fix-asm-srcloc, r=petrochenkov
Browse files Browse the repository at this point in the history
Fix spans for asm diagnostics

Line spans were incorrect if the first line of an asm statement was an
empty string.
  • Loading branch information
Dylan-DPC authored Jul 14, 2022
2 parents ecae3d7 + f4e7813 commit d3a1aa0
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 4 deletions.
4 changes: 2 additions & 2 deletions compiler/rustc_builtin_macros/src/asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -534,8 +534,8 @@ fn expand_preparsed_asm(ecx: &mut ExtCtxt<'_>, args: AsmArgs) -> Option<ast::Inl

let mut template_strs = Vec::with_capacity(args.templates.len());

for template_expr in args.templates.into_iter() {
if !template.is_empty() {
for (i, template_expr) in args.templates.into_iter().enumerate() {
if i != 0 {
template.push(ast::InlineAsmTemplatePiece::String("\n".to_string()));
}

Expand Down
7 changes: 7 additions & 0 deletions src/test/ui/asm/aarch64/srcloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,5 +118,12 @@ fn main() {
//~^^^^^^^^^^ ERROR: unrecognized instruction mnemonic
//~^^^^^^^ ERROR: unrecognized instruction mnemonic
//~^^^^^^^^ ERROR: unrecognized instruction mnemonic

asm!(
"",
"\n",
"invalid_instruction"
);
//~^^ ERROR: unrecognized instruction mnemonic
}
}
14 changes: 13 additions & 1 deletion src/test/ui/asm/aarch64/srcloc.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -274,5 +274,17 @@ note: instantiated into assembly here
LL | invalid_instruction4
| ^

error: aborting due to 23 previous errors
error: unrecognized instruction mnemonic
--> $DIR/srcloc.rs:125:14
|
LL | "invalid_instruction"
| ^
|
note: instantiated into assembly here
--> <inline asm>:4:1
|
LL | invalid_instruction
| ^

error: aborting due to 24 previous errors

7 changes: 7 additions & 0 deletions src/test/ui/asm/x86_64/srcloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,5 +120,12 @@ fn main() {
//~^^^^^^^^^^ ERROR: invalid instruction mnemonic 'invalid_instruction2'
//~^^^^^^^ ERROR: invalid instruction mnemonic 'invalid_instruction3'
//~^^^^^^^^ ERROR: invalid instruction mnemonic 'invalid_instruction4'

asm!(
"",
"\n",
"invalid_instruction"
);
//~^^ ERROR: invalid instruction mnemonic 'invalid_instruction'
}
}
14 changes: 13 additions & 1 deletion src/test/ui/asm/x86_64/srcloc.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -286,5 +286,17 @@ note: instantiated into assembly here
LL | invalid_instruction4
| ^^^^^^^^^^^^^^^^^^^^

error: aborting due to 23 previous errors; 1 warning emitted
error: invalid instruction mnemonic 'invalid_instruction'
--> $DIR/srcloc.rs:127:14
|
LL | "invalid_instruction"
| ^
|
note: instantiated into assembly here
--> <inline asm>:5:1
|
LL | invalid_instruction
| ^^^^^^^^^^^^^^^^^^^

error: aborting due to 24 previous errors; 1 warning emitted

0 comments on commit d3a1aa0

Please sign in to comment.