rustc: improve E0669 span

E0669 refers to a constraint 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.

Signed-off-by: Levente Kurusa <lkurusa@acm.org>
This commit is contained in:
Levente Kurusa 2018-10-15 00:00:53 +02:00
parent 567557f630
commit 4d7f08b170
No known key found for this signature in database
GPG Key ID: 28D6B15E6B491269
8 changed files with 26 additions and 21 deletions

View File

@ -1713,7 +1713,7 @@ pub enum StatementKind<'tcx> {
InlineAsm {
asm: Box<InlineAsm>,
outputs: Box<[Place<'tcx>]>,
inputs: Box<[Operand<'tcx>]>,
inputs: Box<[(Span, Operand<'tcx>)]>,
},
/// Assert the given places to be valid inhabitants of their type. These statements are

View File

@ -383,7 +383,8 @@ fn super_statement(&mut self,
for output in & $($mutability)* outputs[..] {
self.visit_place(output, PlaceContext::AsmOutput, location);
}
for input in & $($mutability)* inputs[..] {
for (span, input) in & $($mutability)* inputs[..] {
self.visit_span(span);
self.visit_operand(input, location);
}
}

View File

@ -84,18 +84,18 @@ pub fn codegen_statement(&mut self,
}).collect();
let input_vals = inputs.iter()
.try_fold(Vec::with_capacity(inputs.len()), |mut acc, input| {
.try_fold(Vec::with_capacity(inputs.len()), |mut acc, (span, input)| {
let op = self.codegen_operand(&bx, input);
if let OperandValue::Immediate(_) = op.val {
acc.push(op.immediate());
Ok(acc)
} else {
Err(op)
Err(span)
}
});
if input_vals.is_err() {
span_err!(bx.sess(), statement.source_info.span, E0669,
if let Err(span) = input_vals {
span_err!(bx.sess(), span.to_owned(), E0669,
"invalid value for constraint in inline assembly");
} else {
let input_vals = input_vals.unwrap();

View File

@ -565,7 +565,7 @@ fn visit_statement_entry(
);
}
}
for input in inputs.iter() {
for (_, input) in inputs.iter() {
self.consume_operand(context, (input, span), flow_state);
}
}

View File

@ -128,7 +128,7 @@ fn visit_statement(&mut self,
);
}
}
for input in inputs.iter() {
for (_, input) in inputs.iter() {
self.consume_operand(context, input);
}
}

View File

@ -167,8 +167,12 @@ pub fn stmt_expr(&mut self, mut block: BasicBlock, expr: Expr<'tcx>) -> BlockAnd
.into_boxed_slice();
let inputs = inputs
.into_iter()
.map(|input| unpack!(block = this.as_local_operand(block, input)))
.collect::<Vec<_>>()
.map(|input| {
(
input.span(),
unpack!(block = this.as_local_operand(block, input)),
)
}).collect::<Vec<_>>()
.into_boxed_slice();
this.cfg.push(
block,

View File

@ -290,7 +290,7 @@ fn gather_statement(&mut self, stmt: &Statement<'tcx>) {
self.gather_init(output, InitKind::Deep);
}
}
for input in inputs.iter() {
for (_, input) in inputs.iter() {
self.gather_operand(input);
}
}

View File

@ -1,32 +1,32 @@
error[E0669]: invalid value for constraint in inline assembly
--> $DIR/inline-asm-bad-operand.rs:28:9
--> $DIR/inline-asm-bad-operand.rs:28:24
|
LL | asm!("" :: "r"("")); //~ ERROR E0669
| ^^^^^^^^^^^^^^^^^^^^
| ^^
error[E0669]: invalid value for constraint in inline assembly
--> $DIR/inline-asm-bad-operand.rs:33:9
--> $DIR/inline-asm-bad-operand.rs:33:32
|
LL | asm!("ret" : : "{rdi}"(target)); //~ ERROR E0669
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| ^^^^^^
error[E0669]: invalid value for constraint in inline assembly
--> $DIR/inline-asm-bad-operand.rs:40:14
--> $DIR/inline-asm-bad-operand.rs:40:29
|
LL | unsafe { asm!("" :: "i"(hello)) }; //~ ERROR E0669
| ^^^^^^^^^^^^^^^^^^^^^^
| ^^^^^
error[E0669]: invalid value for constraint in inline assembly
--> $DIR/inline-asm-bad-operand.rs:48:9
--> $DIR/inline-asm-bad-operand.rs:48:38
|
LL | asm!("movups $1, %xmm0"::"m"(arr)); //~ ERROR E0669
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| ^^^
error[E0669]: invalid value for constraint in inline assembly
--> $DIR/inline-asm-bad-operand.rs:55:9
--> $DIR/inline-asm-bad-operand.rs:55:32
|
LL | asm!("mov sp, $0"::"r"(addr)); //~ ERROR E0669
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| ^^^^
error: aborting due to 5 previous errors