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:
parent
567557f630
commit
4d7f08b170
@ -1713,7 +1713,7 @@ pub enum StatementKind<'tcx> {
|
|||||||
InlineAsm {
|
InlineAsm {
|
||||||
asm: Box<InlineAsm>,
|
asm: Box<InlineAsm>,
|
||||||
outputs: Box<[Place<'tcx>]>,
|
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
|
/// Assert the given places to be valid inhabitants of their type. These statements are
|
||||||
|
@ -383,7 +383,8 @@ fn super_statement(&mut self,
|
|||||||
for output in & $($mutability)* outputs[..] {
|
for output in & $($mutability)* outputs[..] {
|
||||||
self.visit_place(output, PlaceContext::AsmOutput, location);
|
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);
|
self.visit_operand(input, location);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -84,18 +84,18 @@ pub fn codegen_statement(&mut self,
|
|||||||
}).collect();
|
}).collect();
|
||||||
|
|
||||||
let input_vals = inputs.iter()
|
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);
|
let op = self.codegen_operand(&bx, input);
|
||||||
if let OperandValue::Immediate(_) = op.val {
|
if let OperandValue::Immediate(_) = op.val {
|
||||||
acc.push(op.immediate());
|
acc.push(op.immediate());
|
||||||
Ok(acc)
|
Ok(acc)
|
||||||
} else {
|
} else {
|
||||||
Err(op)
|
Err(span)
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if input_vals.is_err() {
|
if let Err(span) = input_vals {
|
||||||
span_err!(bx.sess(), statement.source_info.span, E0669,
|
span_err!(bx.sess(), span.to_owned(), E0669,
|
||||||
"invalid value for constraint in inline assembly");
|
"invalid value for constraint in inline assembly");
|
||||||
} else {
|
} else {
|
||||||
let input_vals = input_vals.unwrap();
|
let input_vals = input_vals.unwrap();
|
||||||
|
@ -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);
|
self.consume_operand(context, (input, span), flow_state);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -128,7 +128,7 @@ fn visit_statement(&mut self,
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for input in inputs.iter() {
|
for (_, input) in inputs.iter() {
|
||||||
self.consume_operand(context, input);
|
self.consume_operand(context, input);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -167,8 +167,12 @@ pub fn stmt_expr(&mut self, mut block: BasicBlock, expr: Expr<'tcx>) -> BlockAnd
|
|||||||
.into_boxed_slice();
|
.into_boxed_slice();
|
||||||
let inputs = inputs
|
let inputs = inputs
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|input| unpack!(block = this.as_local_operand(block, input)))
|
.map(|input| {
|
||||||
.collect::<Vec<_>>()
|
(
|
||||||
|
input.span(),
|
||||||
|
unpack!(block = this.as_local_operand(block, input)),
|
||||||
|
)
|
||||||
|
}).collect::<Vec<_>>()
|
||||||
.into_boxed_slice();
|
.into_boxed_slice();
|
||||||
this.cfg.push(
|
this.cfg.push(
|
||||||
block,
|
block,
|
||||||
|
@ -290,7 +290,7 @@ fn gather_statement(&mut self, stmt: &Statement<'tcx>) {
|
|||||||
self.gather_init(output, InitKind::Deep);
|
self.gather_init(output, InitKind::Deep);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for input in inputs.iter() {
|
for (_, input) in inputs.iter() {
|
||||||
self.gather_operand(input);
|
self.gather_operand(input);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,32 +1,32 @@
|
|||||||
error[E0669]: invalid value for constraint in inline assembly
|
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
|
LL | asm!("" :: "r"("")); //~ ERROR E0669
|
||||||
| ^^^^^^^^^^^^^^^^^^^^
|
| ^^
|
||||||
|
|
||||||
error[E0669]: invalid value for constraint in inline assembly
|
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
|
LL | asm!("ret" : : "{rdi}"(target)); //~ ERROR E0669
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^
|
||||||
|
|
||||||
error[E0669]: invalid value for constraint in inline assembly
|
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
|
LL | unsafe { asm!("" :: "i"(hello)) }; //~ ERROR E0669
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^
|
||||||
|
|
||||||
error[E0669]: invalid value for constraint in inline assembly
|
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
|
LL | asm!("movups $1, %xmm0"::"m"(arr)); //~ ERROR E0669
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^
|
||||||
|
|
||||||
error[E0669]: invalid value for constraint in inline assembly
|
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
|
LL | asm!("mov sp, $0"::"r"(addr)); //~ ERROR E0669
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^
|
||||||
|
|
||||||
error: aborting due to 5 previous errors
|
error: aborting due to 5 previous errors
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user