Skip to content

Commit 8b09631

Browse files
committed
Auto merge of #55087 - levex:e0669-improve-span, r=nagisa
rustc: improve E0669 span E0669 refers to an operand that cannot be coerced into a single LLVM value, unfortunately right now this uses the Span for the entire inline assembly statement, which is less than ideal. This commit preserves the Span from HIR, which lets us emit the error using the Span for the operand itself in MIR. r? @nagisa cc/ @parched
2 parents e53a5ff + 46b9461 commit 8b09631

File tree

9 files changed

+49
-26
lines changed

9 files changed

+49
-26
lines changed

src/librustc/mir/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1751,7 +1751,7 @@ pub enum StatementKind<'tcx> {
17511751
InlineAsm {
17521752
asm: Box<InlineAsm>,
17531753
outputs: Box<[Place<'tcx>]>,
1754-
inputs: Box<[Operand<'tcx>]>,
1754+
inputs: Box<[(Span, Operand<'tcx>)]>,
17551755
},
17561756

17571757
/// Retag references in the given place, ensuring they got fresh tags. This is

src/librustc/mir/visit.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,8 @@ macro_rules! make_mir_visitor {
409409
location
410410
);
411411
}
412-
for input in & $($mutability)* inputs[..] {
412+
for (span, input) in & $($mutability)* inputs[..] {
413+
self.visit_span(span);
413414
self.visit_operand(input, location);
414415
}
415416
}

src/librustc_codegen_llvm/mir/statement.rs

+5-8
Original file line numberDiff line numberDiff line change
@@ -84,21 +84,18 @@ impl FunctionCx<'a, 'll, 'tcx> {
8484
}).collect();
8585

8686
let input_vals = inputs.iter()
87-
.try_fold(Vec::with_capacity(inputs.len()), |mut acc, input| {
87+
.fold(Vec::with_capacity(inputs.len()), |mut acc, (span, input)| {
8888
let op = self.codegen_operand(&bx, input);
8989
if let OperandValue::Immediate(_) = op.val {
9090
acc.push(op.immediate());
91-
Ok(acc)
9291
} else {
93-
Err(op)
92+
span_err!(bx.sess(), span.to_owned(), E0669,
93+
"invalid value for constraint in inline assembly");
9494
}
95+
acc
9596
});
9697

97-
if input_vals.is_err() {
98-
span_err!(bx.sess(), statement.source_info.span, E0669,
99-
"invalid value for constraint in inline assembly");
100-
} else {
101-
let input_vals = input_vals.unwrap();
98+
if input_vals.len() == inputs.len() {
10299
let res = asm::codegen_inline_asm(&bx, asm, outputs, input_vals);
103100
if !res {
104101
span_err!(bx.sess(), statement.source_info.span, E0668,

src/librustc_mir/borrow_check/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,7 @@ impl<'cx, 'gcx, 'tcx> DataflowResultsConsumer<'cx, 'tcx> for MirBorrowckCtxt<'cx
590590
);
591591
}
592592
}
593-
for input in inputs.iter() {
593+
for (_, input) in inputs.iter() {
594594
self.consume_operand(context, (input, span), flow_state);
595595
}
596596
}

src/librustc_mir/borrow_check/nll/invalidation.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ impl<'cx, 'tcx, 'gcx> Visitor<'tcx> for InvalidationGenerator<'cx, 'tcx, 'gcx> {
128128
);
129129
}
130130
}
131-
for input in inputs.iter() {
131+
for (_, input) in inputs.iter() {
132132
self.consume_operand(context, input);
133133
}
134134
}

src/librustc_mir/build/expr/stmt.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,12 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
167167
.into_boxed_slice();
168168
let inputs = inputs
169169
.into_iter()
170-
.map(|input| unpack!(block = this.as_local_operand(block, input)))
171-
.collect::<Vec<_>>()
170+
.map(|input| {
171+
(
172+
input.span(),
173+
unpack!(block = this.as_local_operand(block, input)),
174+
)
175+
}).collect::<Vec<_>>()
172176
.into_boxed_slice();
173177
this.cfg.push(
174178
block,

src/librustc_mir/dataflow/move_paths/builder.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ impl<'b, 'a, 'gcx, 'tcx> Gatherer<'b, 'a, 'gcx, 'tcx> {
289289
self.gather_init(output, InitKind::Deep);
290290
}
291291
}
292-
for input in inputs.iter() {
292+
for (_, input) in inputs.iter() {
293293
self.gather_operand(input);
294294
}
295295
}

src/test/ui/inline-asm-bad-operand.rs

+9
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ fn main() {
2121
issue_37437();
2222
issue_40187();
2323
issue_54067();
24+
multiple_errors();
2425
}
2526

2627
fn issue_37433() {
@@ -55,3 +56,11 @@ fn issue_54067() {
5556
asm!("mov sp, $0"::"r"(addr)); //~ ERROR E0669
5657
}
5758
}
59+
60+
fn multiple_errors() {
61+
let addr: (u32, u32) = (1, 2);
62+
unsafe {
63+
asm!("mov sp, $0"::"r"(addr), //~ ERROR E0669
64+
"r"("hello e0669")); //~ ERROR E0669
65+
}
66+
}
+23-11
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,45 @@
11
error[E0669]: invalid value for constraint in inline assembly
2-
--> $DIR/inline-asm-bad-operand.rs:28:9
2+
--> $DIR/inline-asm-bad-operand.rs:29:24
33
|
44
LL | asm!("" :: "r"("")); //~ ERROR E0669
5-
| ^^^^^^^^^^^^^^^^^^^^
5+
| ^^
66

77
error[E0669]: invalid value for constraint in inline assembly
8-
--> $DIR/inline-asm-bad-operand.rs:33:9
8+
--> $DIR/inline-asm-bad-operand.rs:34:32
99
|
1010
LL | asm!("ret" : : "{rdi}"(target)); //~ ERROR E0669
11-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
11+
| ^^^^^^
1212

1313
error[E0669]: invalid value for constraint in inline assembly
14-
--> $DIR/inline-asm-bad-operand.rs:40:14
14+
--> $DIR/inline-asm-bad-operand.rs:41:29
1515
|
1616
LL | unsafe { asm!("" :: "i"(hello)) }; //~ ERROR E0669
17-
| ^^^^^^^^^^^^^^^^^^^^^^
17+
| ^^^^^
1818

1919
error[E0669]: invalid value for constraint in inline assembly
20-
--> $DIR/inline-asm-bad-operand.rs:48:9
20+
--> $DIR/inline-asm-bad-operand.rs:49:38
2121
|
2222
LL | asm!("movups $1, %xmm0"::"m"(arr)); //~ ERROR E0669
23-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
23+
| ^^^
2424

2525
error[E0669]: invalid value for constraint in inline assembly
26-
--> $DIR/inline-asm-bad-operand.rs:55:9
26+
--> $DIR/inline-asm-bad-operand.rs:56:32
2727
|
2828
LL | asm!("mov sp, $0"::"r"(addr)); //~ ERROR E0669
29-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
29+
| ^^^^
3030

31-
error: aborting due to 5 previous errors
31+
error[E0669]: invalid value for constraint in inline assembly
32+
--> $DIR/inline-asm-bad-operand.rs:63:32
33+
|
34+
LL | asm!("mov sp, $0"::"r"(addr), //~ ERROR E0669
35+
| ^^^^
36+
37+
error[E0669]: invalid value for constraint in inline assembly
38+
--> $DIR/inline-asm-bad-operand.rs:64:32
39+
|
40+
LL | "r"("hello e0669")); //~ ERROR E0669
41+
| ^^^^^^^^^^^^^
42+
43+
error: aborting due to 7 previous errors
3244

3345
For more information about this error, try `rustc --explain E0669`.

0 commit comments

Comments
 (0)