Skip to content

Commit 4425fe4

Browse files
committed
More spans, don't duplicate clobbers
1 parent db8af3f commit 4425fe4

File tree

6 files changed

+41
-18
lines changed

6 files changed

+41
-18
lines changed

compiler/rustc_ast/src/ast.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2705,7 +2705,7 @@ pub enum ItemKind {
27052705
/// E.g., `extern {}` or `extern "C" {}`.
27062706
ForeignMod(ForeignMod),
27072707
/// Module-level inline assembly (from `global_asm!()`).
2708-
GlobalAsm(InlineAsm),
2708+
GlobalAsm(Box<InlineAsm>),
27092709
/// A type alias (`type`).
27102710
///
27112711
/// E.g., `type Foo = Bar<u8>;`.
@@ -2744,7 +2744,7 @@ pub enum ItemKind {
27442744
}
27452745

27462746
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
2747-
rustc_data_structures::static_assert_size!(ItemKind, 128);
2747+
rustc_data_structures::static_assert_size!(ItemKind, 112);
27482748

27492749
impl ItemKind {
27502750
pub fn article(&self) -> &str {

compiler/rustc_ast_lowering/src/asm.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
2828
.emit();
2929
}
3030

31-
let mut clobber_abis = FxHashSet::default();
31+
let mut clobber_abis = FxHashMap::default();
3232
if let Some(asm_arch) = asm_arch {
3333
for &(abi_name, abi_span) in &asm.clobber_abis {
3434
match asm::InlineAsmClobberAbi::parse(asm_arch, &self.sess.target, abi_name) {
3535
Ok(abi) => {
36-
clobber_abis.insert((abi, abi_span));
36+
clobber_abis.insert(abi, abi_span);
3737
}
3838
Err(&[]) => {
3939
self.sess
@@ -371,8 +371,14 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
371371

372372
// If a clobber_abi is specified, add the necessary clobbers to the
373373
// operands list.
374+
let mut clobbered = FxHashSet::default();
374375
for (abi, abi_span) in clobber_abis {
375376
for &clobber in abi.clobbered_regs() {
377+
// Don't emit a clobber for a register already clobbered
378+
if clobbered.contains(&clobber) {
379+
continue;
380+
}
381+
376382
let mut output_used = false;
377383
clobber.overlapping_regs(|reg| {
378384
if used_output_regs.contains_key(&reg) {
@@ -389,6 +395,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
389395
},
390396
self.lower_span(abi_span),
391397
));
398+
clobbered.insert(clobber);
392399
}
393400
}
394401
}

compiler/rustc_builtin_macros/src/asm.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -322,10 +322,12 @@ fn parse_args<'a>(
322322
// Bail out now since this is likely to confuse MIR
323323
return Err(err);
324324
}
325-
if let Some(&(_, abi_span)) = args.clobber_abis.last() {
325+
if args.clobber_abis.len() > 0 {
326326
if is_global_asm {
327-
let err =
328-
ecx.struct_span_err(abi_span, "`clobber_abi` cannot be used with `global_asm!`");
327+
let err = ecx.struct_span_err(
328+
args.clobber_abis.iter().map(|(_, sp)| *sp).collect::<Vec<Span>>(),
329+
"`clobber_abi` cannot be used with `global_asm!`",
330+
);
329331

330332
// Bail out now since this is likely to confuse later stages
331333
return Err(err);
@@ -335,7 +337,10 @@ fn parse_args<'a>(
335337
regclass_outputs.clone(),
336338
"asm with `clobber_abi` must specify explicit registers for outputs",
337339
)
338-
.span_label(abi_span, "clobber_abi")
340+
.span_labels(
341+
args.clobber_abis.iter().map(|(_, sp)| *sp).collect::<Vec<Span>>(),
342+
"clobber_abi",
343+
)
339344
.span_labels(regclass_outputs, "generic outputs")
340345
.emit();
341346
}
@@ -808,7 +813,7 @@ pub fn expand_global_asm<'cx>(
808813
ident: Ident::invalid(),
809814
attrs: Vec::new(),
810815
id: ast::DUMMY_NODE_ID,
811-
kind: ast::ItemKind::GlobalAsm(inline_asm),
816+
kind: ast::ItemKind::GlobalAsm(Box::new(inline_asm)),
812817
vis: ast::Visibility {
813818
span: sp.shrink_to_lo(),
814819
kind: ast::VisibilityKind::Inherited,

src/test/ui/asm/x86_64/bad-options.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ fn main() {
2121
//~^ ERROR invalid ABI for `clobber_abi`
2222
asm!("{}", out(reg) foo, clobber_abi("C"));
2323
//~^ ERROR asm with `clobber_abi` must specify explicit registers for outputs
24+
asm!("{}", out(reg) foo, clobber_abi("C"), clobber_abi("C"));
25+
//~^ ERROR asm with `clobber_abi` must specify explicit registers for outputs
2426
asm!("", out("eax") foo, clobber_abi("C"));
2527
}
2628
}

src/test/ui/asm/x86_64/bad-options.stderr

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,38 +36,47 @@ LL | asm!("{}", out(reg) foo, clobber_abi("C"));
3636
| |
3737
| generic outputs
3838

39+
error: asm with `clobber_abi` must specify explicit registers for outputs
40+
--> $DIR/bad-options.rs:24:20
41+
|
42+
LL | asm!("{}", out(reg) foo, clobber_abi("C"), clobber_abi("C"));
43+
| ^^^^^^^^^^^^ ---------------- ---------------- clobber_abi
44+
| | |
45+
| | clobber_abi
46+
| generic outputs
47+
3948
error: expected one of `)`, `att_syntax`, or `raw`, found `nomem`
40-
--> $DIR/bad-options.rs:28:25
49+
--> $DIR/bad-options.rs:30:25
4150
|
4251
LL | global_asm!("", options(nomem));
4352
| ^^^^^ expected one of `)`, `att_syntax`, or `raw`
4453

4554
error: expected one of `)`, `att_syntax`, or `raw`, found `readonly`
46-
--> $DIR/bad-options.rs:30:25
55+
--> $DIR/bad-options.rs:32:25
4756
|
4857
LL | global_asm!("", options(readonly));
4958
| ^^^^^^^^ expected one of `)`, `att_syntax`, or `raw`
5059

5160
error: expected one of `)`, `att_syntax`, or `raw`, found `noreturn`
52-
--> $DIR/bad-options.rs:32:25
61+
--> $DIR/bad-options.rs:34:25
5362
|
5463
LL | global_asm!("", options(noreturn));
5564
| ^^^^^^^^ expected one of `)`, `att_syntax`, or `raw`
5665

5766
error: expected one of `)`, `att_syntax`, or `raw`, found `pure`
58-
--> $DIR/bad-options.rs:34:25
67+
--> $DIR/bad-options.rs:36:25
5968
|
6069
LL | global_asm!("", options(pure));
6170
| ^^^^ expected one of `)`, `att_syntax`, or `raw`
6271

6372
error: expected one of `)`, `att_syntax`, or `raw`, found `nostack`
64-
--> $DIR/bad-options.rs:36:25
73+
--> $DIR/bad-options.rs:38:25
6574
|
6675
LL | global_asm!("", options(nostack));
6776
| ^^^^^^^ expected one of `)`, `att_syntax`, or `raw`
6877

6978
error: expected one of `)`, `att_syntax`, or `raw`, found `preserves_flags`
70-
--> $DIR/bad-options.rs:38:25
79+
--> $DIR/bad-options.rs:40:25
7180
|
7281
LL | global_asm!("", options(preserves_flags));
7382
| ^^^^^^^^^^^^^^^ expected one of `)`, `att_syntax`, or `raw`
@@ -80,5 +89,5 @@ LL | asm!("", clobber_abi("foo"));
8089
|
8190
= note: the following ABIs are supported on this target: `C`, `system`, `efiapi`, `win64`, `sysv64`
8291

83-
error: aborting due to 13 previous errors
92+
error: aborting due to 14 previous errors
8493

src/test/ui/asm/x86_64/parse-error.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -335,10 +335,10 @@ LL | global_asm!("{}", options(), clobber_abi("C"), const FOO);
335335
| options
336336

337337
error: `clobber_abi` cannot be used with `global_asm!`
338-
--> $DIR/parse-error.rs:121:35
338+
--> $DIR/parse-error.rs:121:17
339339
|
340340
LL | global_asm!("", clobber_abi("C"), clobber_abi("C"));
341-
| ^^^^^^^^^^^^^^^^
341+
| ^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^
342342

343343
error: duplicate argument named `a`
344344
--> $DIR/parse-error.rs:123:35

0 commit comments

Comments
 (0)