1
Fork 0

Retain assembly operands span when lowering AST to HIR

This commit is contained in:
Tomasz Miąsko 2020-11-27 00:00:00 +00:00
parent 0f6f2d681b
commit 91fe548825
13 changed files with 18 additions and 20 deletions

View file

@ -1307,7 +1307,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
hir::InlineAsmOperand::Sym { expr: self.lower_expr_mut(expr) } hir::InlineAsmOperand::Sym { expr: self.lower_expr_mut(expr) }
} }
}; };
Some(op) Some((op, *op_sp))
}) })
.collect(); .collect();
@ -1326,7 +1326,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
} = *p } = *p
{ {
let op_sp = asm.operands[operand_idx].1; let op_sp = asm.operands[operand_idx].1;
match &operands[operand_idx] { match &operands[operand_idx].0 {
hir::InlineAsmOperand::In { reg, .. } hir::InlineAsmOperand::In { reg, .. }
| hir::InlineAsmOperand::Out { reg, .. } | hir::InlineAsmOperand::Out { reg, .. }
| hir::InlineAsmOperand::InOut { reg, .. } | hir::InlineAsmOperand::InOut { reg, .. }
@ -1385,8 +1385,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
let mut used_input_regs = FxHashMap::default(); let mut used_input_regs = FxHashMap::default();
let mut used_output_regs = FxHashMap::default(); let mut used_output_regs = FxHashMap::default();
let mut required_features: Vec<&str> = vec![]; let mut required_features: Vec<&str> = vec![];
for (idx, op) in operands.iter().enumerate() { for (idx, &(ref op, op_sp)) in operands.iter().enumerate() {
let op_sp = asm.operands[idx].1;
if let Some(reg) = op.reg() { if let Some(reg) = op.reg() {
// Make sure we don't accidentally carry features from the // Make sure we don't accidentally carry features from the
// previous iteration. // previous iteration.
@ -1458,8 +1457,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
skip = true; skip = true;
let idx2 = *o.get(); let idx2 = *o.get();
let op2 = &operands[idx2]; let &(ref op2, op_sp2) = &operands[idx2];
let op_sp2 = asm.operands[idx2].1;
let reg2 = match op2.reg() { let reg2 = match op2.reg() {
Some(asm::InlineAsmRegOrRegClass::Reg(r)) => r, Some(asm::InlineAsmRegOrRegClass::Reg(r)) => r,
_ => unreachable!(), _ => unreachable!(),

View file

@ -14,7 +14,7 @@ macro_rules! arena_types {
// HIR types // HIR types
[few] hir_krate: rustc_hir::Crate<$tcx>, [few] hir_krate: rustc_hir::Crate<$tcx>,
[] arm: rustc_hir::Arm<$tcx>, [] arm: rustc_hir::Arm<$tcx>,
[] asm_operand: rustc_hir::InlineAsmOperand<$tcx>, [] asm_operand: (rustc_hir::InlineAsmOperand<$tcx>, Span),
[] asm_template: rustc_ast::InlineAsmTemplatePiece, [] asm_template: rustc_ast::InlineAsmTemplatePiece,
[] attribute: rustc_ast::Attribute, [] attribute: rustc_ast::Attribute,
[] block: rustc_hir::Block<$tcx>, [] block: rustc_hir::Block<$tcx>,

View file

@ -2143,7 +2143,7 @@ impl<'hir> InlineAsmOperand<'hir> {
#[derive(Debug, HashStable_Generic)] #[derive(Debug, HashStable_Generic)]
pub struct InlineAsm<'hir> { pub struct InlineAsm<'hir> {
pub template: &'hir [InlineAsmTemplatePiece], pub template: &'hir [InlineAsmTemplatePiece],
pub operands: &'hir [InlineAsmOperand<'hir>], pub operands: &'hir [(InlineAsmOperand<'hir>, Span)],
pub options: InlineAsmOptions, pub options: InlineAsmOptions,
pub line_spans: &'hir [Span], pub line_spans: &'hir [Span],
} }

View file

@ -1191,7 +1191,7 @@ pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr<'v>)
walk_list!(visitor, visit_expr, optional_expression); walk_list!(visitor, visit_expr, optional_expression);
} }
ExprKind::InlineAsm(ref asm) => { ExprKind::InlineAsm(ref asm) => {
for op in asm.operands { for (op, _op_sp) in asm.operands {
match op { match op {
InlineAsmOperand::In { expr, .. } InlineAsmOperand::In { expr, .. }
| InlineAsmOperand::InOut { expr, .. } | InlineAsmOperand::InOut { expr, .. }

View file

@ -1462,7 +1462,7 @@ impl<'a> State<'a> {
let mut args = vec![]; let mut args = vec![];
args.push(AsmArg::Template(ast::InlineAsmTemplatePiece::to_string(&a.template))); args.push(AsmArg::Template(ast::InlineAsmTemplatePiece::to_string(&a.template)));
args.extend(a.operands.iter().map(|o| AsmArg::Operand(o))); args.extend(a.operands.iter().map(|(o, _)| AsmArg::Operand(o)));
if !a.options.is_empty() { if !a.options.is_empty() {
args.push(AsmArg::Options(a.options)); args.push(AsmArg::Options(a.options));
} }

View file

@ -408,7 +408,7 @@ fn make_mirror_unadjusted<'a, 'tcx>(
operands: asm operands: asm
.operands .operands
.iter() .iter()
.map(|op| { .map(|(op, _op_sp)| {
match *op { match *op {
hir::InlineAsmOperand::In { reg, ref expr } => { hir::InlineAsmOperand::In { reg, ref expr } => {
InlineAsmOperand::In { reg, expr: expr.to_ref() } InlineAsmOperand::In { reg, expr: expr.to_ref() }

View file

@ -347,7 +347,7 @@ impl ExprVisitor<'tcx> {
} }
fn check_asm(&self, asm: &hir::InlineAsm<'tcx>) { fn check_asm(&self, asm: &hir::InlineAsm<'tcx>) {
for (idx, op) in asm.operands.iter().enumerate() { for (idx, (op, _op_sp)) in asm.operands.iter().enumerate() {
match *op { match *op {
hir::InlineAsmOperand::In { reg, ref expr } => { hir::InlineAsmOperand::In { reg, ref expr } => {
self.check_asm_operand_type(idx, reg, expr, asm.template, None); self.check_asm_operand_type(idx, reg, expr, asm.template, None);

View file

@ -1174,7 +1174,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
}; };
// Do a first pass for writing outputs only // Do a first pass for writing outputs only
for op in asm.operands.iter().rev() { for (op, _op_sp) in asm.operands.iter().rev() {
match op { match op {
hir::InlineAsmOperand::In { .. } hir::InlineAsmOperand::In { .. }
| hir::InlineAsmOperand::Const { .. } | hir::InlineAsmOperand::Const { .. }
@ -1197,7 +1197,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
// Then do a second pass for inputs // Then do a second pass for inputs
let mut succ = succ; let mut succ = succ;
for op in asm.operands.iter().rev() { for (op, _op_sp) in asm.operands.iter().rev() {
match op { match op {
hir::InlineAsmOperand::In { expr, .. } hir::InlineAsmOperand::In { expr, .. }
| hir::InlineAsmOperand::Const { expr, .. } | hir::InlineAsmOperand::Const { expr, .. }
@ -1454,7 +1454,7 @@ fn check_expr<'tcx>(this: &mut Liveness<'_, 'tcx>, expr: &'tcx Expr<'tcx>) {
} }
hir::ExprKind::InlineAsm(ref asm) => { hir::ExprKind::InlineAsm(ref asm) => {
for op in asm.operands { for (op, _op_sp) in asm.operands {
match op { match op {
hir::InlineAsmOperand::Out { expr, .. } => { hir::InlineAsmOperand::Out { expr, .. } => {
if let Some(expr) = expr { if let Some(expr) = expr {

View file

@ -1929,7 +1929,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
} }
fn check_expr_asm(&self, asm: &'tcx hir::InlineAsm<'tcx>) -> Ty<'tcx> { fn check_expr_asm(&self, asm: &'tcx hir::InlineAsm<'tcx>) -> Ty<'tcx> {
for op in asm.operands { for (op, _op_sp) in asm.operands {
match op { match op {
hir::InlineAsmOperand::In { expr, .. } | hir::InlineAsmOperand::Const { expr } => { hir::InlineAsmOperand::In { expr, .. } | hir::InlineAsmOperand::Const { expr } => {
self.check_expr_asm_operand(expr, true); self.check_expr_asm_operand(expr, true);

View file

@ -243,7 +243,7 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
} }
hir::ExprKind::InlineAsm(ref asm) => { hir::ExprKind::InlineAsm(ref asm) => {
for op in asm.operands { for (op, _op_sp) in asm.operands {
match op { match op {
hir::InlineAsmOperand::In { expr, .. } hir::InlineAsmOperand::In { expr, .. }
| hir::InlineAsmOperand::Const { expr, .. } | hir::InlineAsmOperand::Const { expr, .. }

View file

@ -768,7 +768,7 @@ fn never_loop_expr(expr: &Expr<'_>, main_loop_id: HirId) -> NeverLoopResult {
ExprKind::InlineAsm(ref asm) => asm ExprKind::InlineAsm(ref asm) => asm
.operands .operands
.iter() .iter()
.map(|o| match o { .map(|(o, _)| match o {
InlineAsmOperand::In { expr, .. } InlineAsmOperand::In { expr, .. }
| InlineAsmOperand::InOut { expr, .. } | InlineAsmOperand::InOut { expr, .. }
| InlineAsmOperand::Const { expr } | InlineAsmOperand::Const { expr }

View file

@ -517,7 +517,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> {
} }
} }
asm.options.hash(&mut self.s); asm.options.hash(&mut self.s);
for op in asm.operands { for (op, _op_sp) in asm.operands {
match op { match op {
InlineAsmOperand::In { reg, expr } => { InlineAsmOperand::In { reg, expr } => {
reg.hash(&mut self.s); reg.hash(&mut self.s);

View file

@ -293,7 +293,7 @@ fn print_expr(cx: &LateContext<'_>, expr: &hir::Expr<'_>, indent: usize) {
println!("{}template: {}", ind, InlineAsmTemplatePiece::to_string(asm.template)); println!("{}template: {}", ind, InlineAsmTemplatePiece::to_string(asm.template));
println!("{}options: {:?}", ind, asm.options); println!("{}options: {:?}", ind, asm.options);
println!("{}operands:", ind); println!("{}operands:", ind);
for op in asm.operands { for (op, _op_sp) in asm.operands {
match op { match op {
hir::InlineAsmOperand::In { expr, .. } hir::InlineAsmOperand::In { expr, .. }
| hir::InlineAsmOperand::InOut { expr, .. } | hir::InlineAsmOperand::InOut { expr, .. }