1
Fork 0

Use AnonConst for asm! constants

This commit is contained in:
Amanieu d'Antras 2021-04-06 05:50:55 +01:00
parent cbd6ec7604
commit 32be124e30
37 changed files with 281 additions and 242 deletions

View file

@ -1998,7 +1998,7 @@ pub enum InlineAsmOperand {
out_expr: Option<P<Expr>>, out_expr: Option<P<Expr>>,
}, },
Const { Const {
expr: P<Expr>, anon_const: AnonConst,
}, },
Sym { Sym {
expr: P<Expr>, expr: P<Expr>,

View file

@ -1252,7 +1252,6 @@ pub fn noop_visit_expr<T: MutVisitor>(
match op { match op {
InlineAsmOperand::In { expr, .. } InlineAsmOperand::In { expr, .. }
| InlineAsmOperand::InOut { expr, .. } | InlineAsmOperand::InOut { expr, .. }
| InlineAsmOperand::Const { expr, .. }
| InlineAsmOperand::Sym { expr, .. } => vis.visit_expr(expr), | InlineAsmOperand::Sym { expr, .. } => vis.visit_expr(expr),
InlineAsmOperand::Out { expr, .. } => { InlineAsmOperand::Out { expr, .. } => {
if let Some(expr) = expr { if let Some(expr) = expr {
@ -1265,6 +1264,7 @@ pub fn noop_visit_expr<T: MutVisitor>(
vis.visit_expr(out_expr); vis.visit_expr(out_expr);
} }
} }
InlineAsmOperand::Const { anon_const, .. } => vis.visit_anon_const(anon_const),
} }
} }
} }

View file

@ -835,7 +835,6 @@ pub fn walk_expr<'a, V: Visitor<'a>>(visitor: &mut V, expression: &'a Expr) {
match op { match op {
InlineAsmOperand::In { expr, .. } InlineAsmOperand::In { expr, .. }
| InlineAsmOperand::InOut { expr, .. } | InlineAsmOperand::InOut { expr, .. }
| InlineAsmOperand::Const { expr, .. }
| InlineAsmOperand::Sym { expr, .. } => visitor.visit_expr(expr), | InlineAsmOperand::Sym { expr, .. } => visitor.visit_expr(expr),
InlineAsmOperand::Out { expr, .. } => { InlineAsmOperand::Out { expr, .. } => {
if let Some(expr) = expr { if let Some(expr) = expr {
@ -848,6 +847,9 @@ pub fn walk_expr<'a, V: Visitor<'a>>(visitor: &mut V, expression: &'a Expr) {
visitor.visit_expr(out_expr); visitor.visit_expr(out_expr);
} }
} }
InlineAsmOperand::Const { anon_const, .. } => {
visitor.visit_anon_const(anon_const)
}
} }
} }
} }

View file

@ -1411,9 +1411,9 @@ impl<'hir> LoweringContext<'_, 'hir> {
out_expr: out_expr.as_ref().map(|expr| self.lower_expr_mut(expr)), out_expr: out_expr.as_ref().map(|expr| self.lower_expr_mut(expr)),
} }
} }
InlineAsmOperand::Const { ref expr } => { InlineAsmOperand::Const { ref anon_const } => hir::InlineAsmOperand::Const {
hir::InlineAsmOperand::Const { expr: self.lower_expr_mut(expr) } anon_const: self.lower_anon_const(anon_const),
} },
InlineAsmOperand::Sym { ref expr } => { InlineAsmOperand::Sym { ref expr } => {
hir::InlineAsmOperand::Sym { expr: self.lower_expr_mut(expr) } hir::InlineAsmOperand::Sym { expr: self.lower_expr_mut(expr) }
} }

View file

@ -2149,10 +2149,10 @@ impl<'a> State<'a> {
None => s.word("_"), None => s.word("_"),
} }
} }
InlineAsmOperand::Const { expr } => { InlineAsmOperand::Const { anon_const } => {
s.word("const"); s.word("const");
s.space(); s.space();
s.print_expr(expr); s.print_expr(&anon_const.value);
} }
InlineAsmOperand::Sym { expr } => { InlineAsmOperand::Sym { expr } => {
s.word("sym"); s.word("sym");

View file

@ -136,8 +136,8 @@ fn parse_args<'a>(
ast::InlineAsmOperand::InOut { reg, expr, late: true } ast::InlineAsmOperand::InOut { reg, expr, late: true }
} }
} else if p.eat_keyword(kw::Const) { } else if p.eat_keyword(kw::Const) {
let expr = p.parse_expr()?; let anon_const = p.parse_anon_const_expr()?;
ast::InlineAsmOperand::Const { expr } ast::InlineAsmOperand::Const { anon_const }
} else if p.eat_keyword(sym::sym) { } else if p.eat_keyword(sym::sym) {
let expr = p.parse_expr()?; let expr = p.parse_expr()?;
match expr.kind { match expr.kind {

View file

@ -822,41 +822,37 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
InlineAsmOperandRef::InOut { reg, late, in_value, out_place } InlineAsmOperandRef::InOut { reg, late, in_value, out_place }
} }
mir::InlineAsmOperand::Const { ref value } => { mir::InlineAsmOperand::Const { ref value } => {
if let mir::Operand::Constant(constant) = value { let const_value = self
let const_value = self .eval_mir_constant(value)
.eval_mir_constant(constant) .unwrap_or_else(|_| span_bug!(span, "asm const cannot be resolved"));
.unwrap_or_else(|_| span_bug!(span, "asm const cannot be resolved")); let ty = value.ty();
let ty = constant.ty(); let size = bx.layout_of(ty).size;
let size = bx.layout_of(ty).size; let scalar = match const_value {
let scalar = match const_value { ConstValue::Scalar(s) => s,
ConstValue::Scalar(s) => s, _ => span_bug!(
_ => span_bug!( span,
span, "expected Scalar for promoted asm const, but got {:#?}",
"expected Scalar for promoted asm const, but got {:#?}", const_value
const_value ),
), };
}; let value = scalar.assert_bits(size);
let value = scalar.assert_bits(size); let string = match ty.kind() {
let string = match ty.kind() { ty::Uint(_) => value.to_string(),
ty::Uint(_) => value.to_string(), ty::Int(int_ty) => {
ty::Int(int_ty) => { match int_ty.normalize(bx.tcx().sess.target.pointer_width) {
match int_ty.normalize(bx.tcx().sess.target.pointer_width) { ty::IntTy::I8 => (value as i8).to_string(),
ty::IntTy::I8 => (value as i8).to_string(), ty::IntTy::I16 => (value as i16).to_string(),
ty::IntTy::I16 => (value as i16).to_string(), ty::IntTy::I32 => (value as i32).to_string(),
ty::IntTy::I32 => (value as i32).to_string(), ty::IntTy::I64 => (value as i64).to_string(),
ty::IntTy::I64 => (value as i64).to_string(), ty::IntTy::I128 => (value as i128).to_string(),
ty::IntTy::I128 => (value as i128).to_string(), ty::IntTy::Isize => unreachable!(),
ty::IntTy::Isize => unreachable!(),
}
} }
ty::Float(ty::FloatTy::F32) => f32::from_bits(value as u32).to_string(), }
ty::Float(ty::FloatTy::F64) => f64::from_bits(value as u64).to_string(), ty::Float(ty::FloatTy::F32) => f32::from_bits(value as u32).to_string(),
_ => span_bug!(span, "asm const has bad type {}", ty), ty::Float(ty::FloatTy::F64) => f64::from_bits(value as u64).to_string(),
}; _ => span_bug!(span, "asm const has bad type {}", ty),
InlineAsmOperandRef::Const { string } };
} else { InlineAsmOperandRef::Const { string }
span_bug!(span, "asm const is not a constant");
}
} }
mir::InlineAsmOperand::SymFn { ref value } => { mir::InlineAsmOperand::SymFn { ref value } => {
let literal = self.monomorphize(value.literal); let literal = self.monomorphize(value.literal);

View file

@ -2347,7 +2347,7 @@ pub enum InlineAsmOperand<'hir> {
out_expr: Option<Expr<'hir>>, out_expr: Option<Expr<'hir>>,
}, },
Const { Const {
expr: Expr<'hir>, anon_const: AnonConst,
}, },
Sym { Sym {
expr: Expr<'hir>, expr: Expr<'hir>,

View file

@ -1189,7 +1189,6 @@ pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr<'v>)
match op { match op {
InlineAsmOperand::In { expr, .. } InlineAsmOperand::In { expr, .. }
| InlineAsmOperand::InOut { expr, .. } | InlineAsmOperand::InOut { expr, .. }
| InlineAsmOperand::Const { expr, .. }
| InlineAsmOperand::Sym { expr, .. } => visitor.visit_expr(expr), | InlineAsmOperand::Sym { expr, .. } => visitor.visit_expr(expr),
InlineAsmOperand::Out { expr, .. } => { InlineAsmOperand::Out { expr, .. } => {
if let Some(expr) = expr { if let Some(expr) = expr {
@ -1202,6 +1201,9 @@ pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr<'v>)
visitor.visit_expr(out_expr); visitor.visit_expr(out_expr);
} }
} }
InlineAsmOperand::Const { anon_const, .. } => {
visitor.visit_anon_const(anon_const)
}
} }
} }
} }

View file

@ -1570,10 +1570,10 @@ impl<'a> State<'a> {
None => s.word("_"), None => s.word("_"),
} }
} }
hir::InlineAsmOperand::Const { expr } => { hir::InlineAsmOperand::Const { anon_const } => {
s.word("const"); s.word("const");
s.space(); s.space();
s.print_expr(expr); s.print_anon_const(anon_const);
} }
hir::InlineAsmOperand::Sym { expr } => { hir::InlineAsmOperand::Sym { expr } => {
s.word("sym"); s.word("sym");

View file

@ -1213,7 +1213,7 @@ pub enum InlineAsmOperand<'tcx> {
out_place: Option<Place<'tcx>>, out_place: Option<Place<'tcx>>,
}, },
Const { Const {
value: Operand<'tcx>, value: Box<Constant<'tcx>>,
}, },
SymFn { SymFn {
value: Box<Constant<'tcx>>, value: Box<Constant<'tcx>>,

View file

@ -584,8 +584,7 @@ macro_rules! make_mir_visitor {
} => { } => {
for op in operands { for op in operands {
match op { match op {
InlineAsmOperand::In { value, .. } InlineAsmOperand::In { value, .. } => {
| InlineAsmOperand::Const { value } => {
self.visit_operand(value, location); self.visit_operand(value, location);
} }
InlineAsmOperand::Out { place, .. } => { InlineAsmOperand::Out { place, .. } => {
@ -607,7 +606,8 @@ macro_rules! make_mir_visitor {
); );
} }
} }
InlineAsmOperand::SymFn { value } => { InlineAsmOperand::Const { value }
| InlineAsmOperand::SymFn { value } => {
self.visit_constant(value, location); self.visit_constant(value, location);
} }
InlineAsmOperand::SymStatic { def_id: _ } => {} InlineAsmOperand::SymStatic { def_id: _ } => {}

View file

@ -204,8 +204,7 @@ impl<'cx, 'tcx> Visitor<'tcx> for InvalidationGenerator<'cx, 'tcx> {
} => { } => {
for op in operands { for op in operands {
match *op { match *op {
InlineAsmOperand::In { reg: _, ref value } InlineAsmOperand::In { reg: _, ref value } => {
| InlineAsmOperand::Const { ref value } => {
self.consume_operand(location, value); self.consume_operand(location, value);
} }
InlineAsmOperand::Out { reg: _, late: _, place, .. } => { InlineAsmOperand::Out { reg: _, late: _, place, .. } => {
@ -219,7 +218,8 @@ impl<'cx, 'tcx> Visitor<'tcx> for InvalidationGenerator<'cx, 'tcx> {
self.mutate_place(location, out_place, Shallow(None), JustWrite); self.mutate_place(location, out_place, Shallow(None), JustWrite);
} }
} }
InlineAsmOperand::SymFn { value: _ } InlineAsmOperand::Const { value: _ }
| InlineAsmOperand::SymFn { value: _ }
| InlineAsmOperand::SymStatic { def_id: _ } => {} | InlineAsmOperand::SymStatic { def_id: _ } => {}
} }
} }

View file

@ -734,8 +734,7 @@ impl<'cx, 'tcx> dataflow::ResultsVisitor<'cx, 'tcx> for MirBorrowckCtxt<'cx, 'tc
} => { } => {
for op in operands { for op in operands {
match *op { match *op {
InlineAsmOperand::In { reg: _, ref value } InlineAsmOperand::In { reg: _, ref value } => {
| InlineAsmOperand::Const { ref value } => {
self.consume_operand(loc, (value, span), flow_state); self.consume_operand(loc, (value, span), flow_state);
} }
InlineAsmOperand::Out { reg: _, late: _, place, .. } => { InlineAsmOperand::Out { reg: _, late: _, place, .. } => {
@ -761,7 +760,8 @@ impl<'cx, 'tcx> dataflow::ResultsVisitor<'cx, 'tcx> for MirBorrowckCtxt<'cx, 'tc
); );
} }
} }
InlineAsmOperand::SymFn { value: _ } InlineAsmOperand::Const { value: _ }
| InlineAsmOperand::SymFn { value: _ }
| InlineAsmOperand::SymStatic { def_id: _ } => {} | InlineAsmOperand::SymStatic { def_id: _ } => {}
} }
} }

View file

@ -425,7 +425,7 @@ impl<'b, 'a, 'tcx> Gatherer<'b, 'a, 'tcx> {
for op in operands { for op in operands {
match *op { match *op {
InlineAsmOperand::In { reg: _, ref value } InlineAsmOperand::In { reg: _, ref value }
| InlineAsmOperand::Const { ref value } => { => {
self.gather_operand(value); self.gather_operand(value);
} }
InlineAsmOperand::Out { reg: _, late: _, place, .. } => { InlineAsmOperand::Out { reg: _, late: _, place, .. } => {
@ -441,7 +441,8 @@ impl<'b, 'a, 'tcx> Gatherer<'b, 'a, 'tcx> {
self.gather_init(out_place.as_ref(), InitKind::Deep); self.gather_init(out_place.as_ref(), InitKind::Deep);
} }
} }
InlineAsmOperand::SymFn { value: _ } InlineAsmOperand::Const { value: _ }
| InlineAsmOperand::SymFn { value: _ }
| InlineAsmOperand::SymStatic { def_id: _ } => {} | InlineAsmOperand::SymStatic { def_id: _ } => {}
} }
} }

View file

@ -720,9 +720,6 @@ impl Conflicts<'a> {
} }
} }
} }
InlineAsmOperand::Const { value } => {
assert!(value.place().is_none());
}
InlineAsmOperand::InOut { InlineAsmOperand::InOut {
reg: _, reg: _,
late: _, late: _,
@ -731,6 +728,7 @@ impl Conflicts<'a> {
} }
| InlineAsmOperand::In { reg: _, value: _ } | InlineAsmOperand::In { reg: _, value: _ }
| InlineAsmOperand::Out { reg: _, late: _, place: None } | InlineAsmOperand::Out { reg: _, late: _, place: None }
| InlineAsmOperand::Const { value: _ }
| InlineAsmOperand::SymFn { value: _ } | InlineAsmOperand::SymFn { value: _ }
| InlineAsmOperand::SymStatic { def_id: _ } => {} | InlineAsmOperand::SymStatic { def_id: _ } => {}
} }

View file

@ -108,9 +108,6 @@ pub enum Candidate {
/// the attribute currently provides the semantic requirement that arguments /// the attribute currently provides the semantic requirement that arguments
/// must be constant. /// must be constant.
Argument { bb: BasicBlock, index: usize }, Argument { bb: BasicBlock, index: usize },
/// `const` operand in asm!.
InlineAsm { bb: BasicBlock, index: usize },
} }
impl Candidate { impl Candidate {
@ -118,16 +115,14 @@ impl Candidate {
fn forces_explicit_promotion(&self) -> bool { fn forces_explicit_promotion(&self) -> bool {
match self { match self {
Candidate::Ref(_) => false, Candidate::Ref(_) => false,
Candidate::Argument { .. } | Candidate::InlineAsm { .. } => true, Candidate::Argument { .. } => true,
} }
} }
fn source_info(&self, body: &Body<'_>) -> SourceInfo { fn source_info(&self, body: &Body<'_>) -> SourceInfo {
match self { match self {
Candidate::Ref(location) => *body.source_info(*location), Candidate::Ref(location) => *body.source_info(*location),
Candidate::Argument { bb, .. } | Candidate::InlineAsm { bb, .. } => { Candidate::Argument { bb, .. } => *body.source_info(body.terminator_loc(*bb)),
*body.source_info(body.terminator_loc(*bb))
}
} }
} }
} }
@ -217,36 +212,25 @@ impl<'tcx> Visitor<'tcx> for Collector<'_, 'tcx> {
fn visit_terminator(&mut self, terminator: &Terminator<'tcx>, location: Location) { fn visit_terminator(&mut self, terminator: &Terminator<'tcx>, location: Location) {
self.super_terminator(terminator, location); self.super_terminator(terminator, location);
match terminator.kind { if let TerminatorKind::Call { ref func, .. } = terminator.kind {
TerminatorKind::Call { ref func, .. } => { if let ty::FnDef(def_id, _) = *func.ty(self.ccx.body, self.ccx.tcx).kind() {
if let ty::FnDef(def_id, _) = *func.ty(self.ccx.body, self.ccx.tcx).kind() { let fn_sig = self.ccx.tcx.fn_sig(def_id);
let fn_sig = self.ccx.tcx.fn_sig(def_id); if let Abi::RustIntrinsic | Abi::PlatformIntrinsic = fn_sig.abi() {
if let Abi::RustIntrinsic | Abi::PlatformIntrinsic = fn_sig.abi() { let name = self.ccx.tcx.item_name(def_id);
let name = self.ccx.tcx.item_name(def_id); // FIXME(eddyb) use `#[rustc_args_required_const(2)]` for shuffles.
// FIXME(eddyb) use `#[rustc_args_required_const(2)]` for shuffles. if name.as_str().starts_with("simd_shuffle") {
if name.as_str().starts_with("simd_shuffle") { self.candidates.push(Candidate::Argument { bb: location.block, index: 2 });
self.candidates
.push(Candidate::Argument { bb: location.block, index: 2 });
return; // Don't double count `simd_shuffle` candidates return; // Don't double count `simd_shuffle` candidates
}
} }
}
if let Some(constant_args) = args_required_const(self.ccx.tcx, def_id) { if let Some(constant_args) = args_required_const(self.ccx.tcx, def_id) {
for index in constant_args { for index in constant_args {
self.candidates.push(Candidate::Argument { bb: location.block, index }); self.candidates.push(Candidate::Argument { bb: location.block, index });
}
} }
} }
} }
TerminatorKind::InlineAsm { ref operands, .. } => {
for (index, op) in operands.iter().enumerate() {
if let InlineAsmOperand::Const { .. } = op {
self.candidates.push(Candidate::InlineAsm { bb: location.block, index })
}
}
}
_ => {}
} }
} }
} }
@ -335,18 +319,6 @@ impl<'tcx> Validator<'_, 'tcx> {
_ => bug!(), _ => bug!(),
} }
} }
Candidate::InlineAsm { bb, index } => {
assert!(self.explicit);
let terminator = self.body[bb].terminator();
match &terminator.kind {
TerminatorKind::InlineAsm { operands, .. } => match &operands[index] {
InlineAsmOperand::Const { value } => self.validate_operand(value),
_ => bug!(),
},
_ => bug!(),
}
}
} }
} }
@ -818,9 +790,7 @@ pub fn validate_candidates(
} }
match candidate { match candidate {
Candidate::Argument { bb, index } | Candidate::InlineAsm { bb, index } Candidate::Argument { bb, index } if !is_promotable => {
if !is_promotable =>
{
let span = ccx.body[bb].terminator().source_info.span; let span = ccx.body[bb].terminator().source_info.span;
let msg = format!("argument {} is required to be a constant", index + 1); let msg = format!("argument {} is required to be a constant", index + 1);
ccx.tcx.sess.span_err(span, &msg); ccx.tcx.sess.span_err(span, &msg);
@ -1089,24 +1059,6 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> {
_ => bug!(), _ => bug!(),
} }
} }
Candidate::InlineAsm { bb, index } => {
let terminator = blocks[bb].terminator_mut();
match terminator.kind {
TerminatorKind::InlineAsm { ref mut operands, .. } => {
match &mut operands[index] {
InlineAsmOperand::Const { ref mut value } => {
let ty = value.ty(local_decls, self.tcx);
let span = terminator.source_info.span;
Rvalue::Use(mem::replace(value, promoted_operand(ty, span)))
}
_ => bug!(),
}
}
_ => bug!(),
}
}
} }
}; };
@ -1161,7 +1113,7 @@ pub fn promote_candidates<'tcx>(
} }
} }
} }
Candidate::Argument { .. } | Candidate::InlineAsm { .. } => {} Candidate::Argument { .. } => {}
} }
// Declare return place local so that `mir::Body::new` doesn't complain. // Declare return place local so that `mir::Body::new` doesn't complain.

View file

@ -366,9 +366,11 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
}), }),
} }
} }
thir::InlineAsmOperand::Const { expr } => mir::InlineAsmOperand::Const { thir::InlineAsmOperand::Const { value, span } => {
value: unpack!(block = this.as_local_operand(block, expr)), mir::InlineAsmOperand::Const {
}, value: box Constant { span, user_ty: None, literal: value.into() },
}
}
thir::InlineAsmOperand::SymFn { expr } => { thir::InlineAsmOperand::SymFn { expr } => {
mir::InlineAsmOperand::SymFn { value: box this.as_constant(expr) } mir::InlineAsmOperand::SymFn { value: box this.as_constant(expr) }
} }

View file

@ -503,8 +503,12 @@ impl<'thir, 'tcx> Cx<'thir, 'tcx> {
in_expr: self.mirror_expr(in_expr), in_expr: self.mirror_expr(in_expr),
out_expr: out_expr.as_ref().map(|expr| self.mirror_expr(expr)), out_expr: out_expr.as_ref().map(|expr| self.mirror_expr(expr)),
}, },
hir::InlineAsmOperand::Const { ref expr } => { hir::InlineAsmOperand::Const { ref anon_const } => {
InlineAsmOperand::Const { expr: self.mirror_expr(expr) } let anon_const_def_id = self.tcx.hir().local_def_id(anon_const.hir_id);
let value = ty::Const::from_anon_const(self.tcx, anon_const_def_id);
let span = self.tcx.hir().span(anon_const.hir_id);
InlineAsmOperand::Const { value, span }
} }
hir::InlineAsmOperand::Sym { ref expr } => { hir::InlineAsmOperand::Sym { ref expr } => {
let qpath = match expr.kind { let qpath = match expr.kind {

View file

@ -374,7 +374,8 @@ pub enum InlineAsmOperand<'thir, 'tcx> {
out_expr: Option<&'thir Expr<'thir, 'tcx>>, out_expr: Option<&'thir Expr<'thir, 'tcx>>,
}, },
Const { Const {
expr: &'thir Expr<'thir, 'tcx>, value: &'tcx Const<'tcx>,
span: Span,
}, },
SymFn { SymFn {
expr: &'thir Expr<'thir, 'tcx>, expr: &'thir Expr<'thir, 'tcx>,

View file

@ -107,7 +107,7 @@ impl<'a> Parser<'a> {
} }
} }
pub(super) fn parse_anon_const_expr(&mut self) -> PResult<'a, AnonConst> { pub fn parse_anon_const_expr(&mut self) -> PResult<'a, AnonConst> {
self.parse_expr().map(|value| AnonConst { id: DUMMY_NODE_ID, value }) self.parse_expr().map(|value| AnonConst { id: DUMMY_NODE_ID, value })
} }

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, _op_sp)) 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);
@ -372,14 +372,15 @@ impl ExprVisitor<'tcx> {
); );
} }
} }
hir::InlineAsmOperand::Const { ref expr } => { hir::InlineAsmOperand::Const { ref anon_const } => {
let ty = self.typeck_results.expr_ty_adjusted(expr); let anon_const_def_id = self.tcx.hir().local_def_id(anon_const.hir_id);
match ty.kind() { let value = ty::Const::from_anon_const(self.tcx, anon_const_def_id);
match value.ty.kind() {
ty::Int(_) | ty::Uint(_) | ty::Float(_) => {} ty::Int(_) | ty::Uint(_) | ty::Float(_) => {}
_ => { _ => {
let msg = let msg =
"asm `const` arguments must be integer or floating-point values"; "asm `const` arguments must be integer or floating-point values";
self.tcx.sess.span_err(expr.span, msg); self.tcx.sess.span_err(*op_sp, msg);
} }
} }
} }

View file

@ -1067,7 +1067,6 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
for (op, _op_sp) 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::Sym { expr, .. } => { | hir::InlineAsmOperand::Sym { expr, .. } => {
succ = self.propagate_through_expr(expr, succ) succ = self.propagate_through_expr(expr, succ)
} }
@ -1085,6 +1084,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
} }
succ = self.propagate_through_expr(in_expr, succ); succ = self.propagate_through_expr(in_expr, succ);
} }
hir::InlineAsmOperand::Const { .. } => {}
} }
} }
succ succ

View file

@ -2087,7 +2087,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, _op_sp) 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, .. } => {
self.check_expr_asm_operand(expr, true); self.check_expr_asm_operand(expr, true);
} }
hir::InlineAsmOperand::Out { expr, .. } => { hir::InlineAsmOperand::Out { expr, .. } => {
@ -2104,6 +2104,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
self.check_expr_asm_operand(out_expr, false); self.check_expr_asm_operand(out_expr, false);
} }
} }
hir::InlineAsmOperand::Const { anon_const } => {
self.to_const(anon_const);
}
hir::InlineAsmOperand::Sym { expr } => { hir::InlineAsmOperand::Sym { expr } => {
self.check_expr(expr); self.check_expr(expr);
} }

View file

@ -540,6 +540,19 @@ fn typeck_with_fallback<'tcx>(
kind: TypeVariableOriginKind::TypeInference, kind: TypeVariableOriginKind::TypeInference,
span, span,
}), }),
Node::Expr(&hir::Expr { kind: hir::ExprKind::InlineAsm(ia), .. })
if ia.operands.iter().any(|(op, _op_sp)| match op {
hir::InlineAsmOperand::Const { anon_const } => {
anon_const.hir_id == id
}
_ => false,
}) =>
{
fcx.next_ty_var(TypeVariableOrigin {
kind: TypeVariableOriginKind::MiscVariable,
span,
})
}
_ => fallback(), _ => fallback(),
}, },
_ => fallback(), _ => fallback(),

View file

@ -430,6 +430,15 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
tcx.typeck(def_id).node_type(anon_const.hir_id) tcx.typeck(def_id).node_type(anon_const.hir_id)
} }
Node::Expr(&Expr { kind: ExprKind::InlineAsm(ia), .. })
if ia.operands.iter().any(|(op, _op_sp)| match op {
hir::InlineAsmOperand::Const { anon_const } => anon_const.hir_id == hir_id,
_ => false,
}) =>
{
tcx.typeck(def_id).node_type(hir_id)
}
Node::Variant(Variant { disr_expr: Some(ref e), .. }) if e.hir_id == hir_id => tcx Node::Variant(Variant { disr_expr: Some(ref e), .. }) if e.hir_id == hir_id => tcx
.adt_def(tcx.hir().get_parent_did(hir_id).to_def_id()) .adt_def(tcx.hir().get_parent_did(hir_id).to_def_id())
.repr .repr

View file

@ -313,7 +313,6 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
for (op, _op_sp) 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::Sym { expr, .. } => self.consume_expr(expr), | hir::InlineAsmOperand::Sym { expr, .. } => self.consume_expr(expr),
hir::InlineAsmOperand::Out { expr, .. } => { hir::InlineAsmOperand::Out { expr, .. } => {
if let Some(expr) = expr { if let Some(expr) = expr {
@ -329,6 +328,7 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
self.mutate_expr(out_expr); self.mutate_expr(out_expr);
} }
} }
hir::InlineAsmOperand::Const { .. } => {}
} }
} }
} }

View file

@ -4,38 +4,18 @@
#![feature(asm)] #![feature(asm)]
use std::mem::size_of; fn const_generic<const X: usize>() -> usize {
unsafe {
trait Proj { let a: usize;
const C: usize; asm!("mov {}, {}", out(reg) a, const X);
} a
impl Proj for i8 { }
const C: usize = 8;
}
impl Proj for i16 {
const C: usize = 16;
} }
const fn constfn(x: usize) -> usize { const fn constfn(x: usize) -> usize {
x x
} }
fn generic<T: Proj>() {
unsafe {
let a: usize;
asm!("mov {}, {}", out(reg) a, const size_of::<T>());
assert_eq!(a, size_of::<T>());
let b: usize;
asm!("mov {}, {}", out(reg) b, const size_of::<T>() + constfn(5));
assert_eq!(b, size_of::<T>() + 5);
let c: usize;
asm!("mov {}, {}", out(reg) c, const T::C);
assert_eq!(c, T::C);
}
}
fn main() { fn main() {
unsafe { unsafe {
let a: usize; let a: usize;
@ -51,6 +31,6 @@ fn main() {
assert_eq!(c, 10); assert_eq!(c, 10);
} }
generic::<i8>(); let d = const_generic::<5>();
generic::<i16>(); assert_eq!(d, 5);
} }

View file

@ -36,17 +36,23 @@ fn main() {
//~^ ERROR expected one of //~^ ERROR expected one of
asm!("{}", options(), const foo); asm!("{}", options(), const foo);
//~^ ERROR arguments are not allowed after options //~^ ERROR arguments are not allowed after options
//~^^ ERROR attempt to use a non-constant value in a constant
asm!("{a}", a = const foo, a = const bar); asm!("{a}", a = const foo, a = const bar);
//~^ ERROR duplicate argument named `a` //~^ ERROR duplicate argument named `a`
//~^^ ERROR argument never used //~^^ ERROR argument never used
//~^^^ ERROR attempt to use a non-constant value in a constant
//~^^^^ ERROR attempt to use a non-constant value in a constant
asm!("", a = in("eax") foo); asm!("", a = in("eax") foo);
//~^ ERROR explicit register arguments cannot have names //~^ ERROR explicit register arguments cannot have names
asm!("{a}", in("eax") foo, a = const bar); asm!("{a}", in("eax") foo, a = const bar);
//~^ ERROR named arguments cannot follow explicit register arguments //~^ ERROR named arguments cannot follow explicit register arguments
//~^^ ERROR attempt to use a non-constant value in a constant
asm!("{a}", in("eax") foo, a = const bar); asm!("{a}", in("eax") foo, a = const bar);
//~^ ERROR named arguments cannot follow explicit register arguments //~^ ERROR named arguments cannot follow explicit register arguments
//~^^ ERROR attempt to use a non-constant value in a constant
asm!("{1}", in("eax") foo, const bar); asm!("{1}", in("eax") foo, const bar);
//~^ ERROR positional arguments cannot follow named arguments or explicit register arguments //~^ ERROR positional arguments cannot follow named arguments or explicit register arguments
//~^^ ERROR attempt to use a non-constant value in a constant
asm!("", options(), ""); asm!("", options(), "");
//~^ ERROR expected one of //~^ ERROR expected one of
asm!("{}", in(reg) foo, "{}", out(reg) foo); asm!("{}", in(reg) foo, "{}", out(reg) foo);

View file

@ -91,7 +91,7 @@ LL | asm!("{}", options(), const foo);
| previous options | previous options
error: duplicate argument named `a` error: duplicate argument named `a`
--> $DIR/parse-error.rs:39:36 --> $DIR/parse-error.rs:40:36
| |
LL | asm!("{a}", a = const foo, a = const bar); LL | asm!("{a}", a = const foo, a = const bar);
| ------------- ^^^^^^^^^^^^^ duplicate argument | ------------- ^^^^^^^^^^^^^ duplicate argument
@ -99,7 +99,7 @@ LL | asm!("{a}", a = const foo, a = const bar);
| previously here | previously here
error: argument never used error: argument never used
--> $DIR/parse-error.rs:39:36 --> $DIR/parse-error.rs:40:36
| |
LL | asm!("{a}", a = const foo, a = const bar); LL | asm!("{a}", a = const foo, a = const bar);
| ^^^^^^^^^^^^^ argument never used | ^^^^^^^^^^^^^ argument never used
@ -107,13 +107,13 @@ LL | asm!("{a}", a = const foo, a = const bar);
= help: if this argument is intentionally unused, consider using it in an asm comment: `"/* {1} */"` = help: if this argument is intentionally unused, consider using it in an asm comment: `"/* {1} */"`
error: explicit register arguments cannot have names error: explicit register arguments cannot have names
--> $DIR/parse-error.rs:42:18 --> $DIR/parse-error.rs:45:18
| |
LL | asm!("", a = in("eax") foo); LL | asm!("", a = in("eax") foo);
| ^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^
error: named arguments cannot follow explicit register arguments error: named arguments cannot follow explicit register arguments
--> $DIR/parse-error.rs:44:36 --> $DIR/parse-error.rs:47:36
| |
LL | asm!("{a}", in("eax") foo, a = const bar); LL | asm!("{a}", in("eax") foo, a = const bar);
| ------------- ^^^^^^^^^^^^^ named argument | ------------- ^^^^^^^^^^^^^ named argument
@ -121,7 +121,7 @@ LL | asm!("{a}", in("eax") foo, a = const bar);
| explicit register argument | explicit register argument
error: named arguments cannot follow explicit register arguments error: named arguments cannot follow explicit register arguments
--> $DIR/parse-error.rs:46:36 --> $DIR/parse-error.rs:50:36
| |
LL | asm!("{a}", in("eax") foo, a = const bar); LL | asm!("{a}", in("eax") foo, a = const bar);
| ------------- ^^^^^^^^^^^^^ named argument | ------------- ^^^^^^^^^^^^^ named argument
@ -129,7 +129,7 @@ LL | asm!("{a}", in("eax") foo, a = const bar);
| explicit register argument | explicit register argument
error: positional arguments cannot follow named arguments or explicit register arguments error: positional arguments cannot follow named arguments or explicit register arguments
--> $DIR/parse-error.rs:48:36 --> $DIR/parse-error.rs:53:36
| |
LL | asm!("{1}", in("eax") foo, const bar); LL | asm!("{1}", in("eax") foo, const bar);
| ------------- ^^^^^^^^^ positional argument | ------------- ^^^^^^^^^ positional argument
@ -137,19 +137,19 @@ LL | asm!("{1}", in("eax") foo, const bar);
| explicit register argument | explicit register argument
error: expected one of `const`, `in`, `inlateout`, `inout`, `lateout`, `options`, `out`, or `sym`, found `""` error: expected one of `const`, `in`, `inlateout`, `inout`, `lateout`, `options`, `out`, or `sym`, found `""`
--> $DIR/parse-error.rs:50:29 --> $DIR/parse-error.rs:56:29
| |
LL | asm!("", options(), ""); LL | asm!("", options(), "");
| ^^ expected one of 8 possible tokens | ^^ expected one of 8 possible tokens
error: expected one of `const`, `in`, `inlateout`, `inout`, `lateout`, `options`, `out`, or `sym`, found `"{}"` error: expected one of `const`, `in`, `inlateout`, `inout`, `lateout`, `options`, `out`, or `sym`, found `"{}"`
--> $DIR/parse-error.rs:52:33 --> $DIR/parse-error.rs:58:33
| |
LL | asm!("{}", in(reg) foo, "{}", out(reg) foo); LL | asm!("{}", in(reg) foo, "{}", out(reg) foo);
| ^^^^ expected one of 8 possible tokens | ^^^^ expected one of 8 possible tokens
error: asm template must be a string literal error: asm template must be a string literal
--> $DIR/parse-error.rs:54:14 --> $DIR/parse-error.rs:60:14
| |
LL | asm!(format!("{{{}}}", 0), in(reg) foo); LL | asm!(format!("{{{}}}", 0), in(reg) foo);
| ^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^
@ -157,12 +157,67 @@ LL | asm!(format!("{{{}}}", 0), in(reg) foo);
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
error: asm template must be a string literal error: asm template must be a string literal
--> $DIR/parse-error.rs:56:21 --> $DIR/parse-error.rs:62:21
| |
LL | asm!("{1}", format!("{{{}}}", 0), in(reg) foo, out(reg) bar); LL | asm!("{1}", format!("{{{}}}", 0), in(reg) foo, out(reg) bar);
| ^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^
| |
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
error: aborting due to 25 previous errors error[E0435]: attempt to use a non-constant value in a constant
--> $DIR/parse-error.rs:37:37
|
LL | let mut foo = 0;
| ---------- help: consider using `const` instead of `let`: `const foo`
...
LL | asm!("{}", options(), const foo);
| ^^^ non-constant value
error[E0435]: attempt to use a non-constant value in a constant
--> $DIR/parse-error.rs:40:31
|
LL | let mut foo = 0;
| ---------- help: consider using `const` instead of `let`: `const foo`
...
LL | asm!("{a}", a = const foo, a = const bar);
| ^^^ non-constant value
error[E0435]: attempt to use a non-constant value in a constant
--> $DIR/parse-error.rs:40:46
|
LL | let mut bar = 0;
| ---------- help: consider using `const` instead of `let`: `const bar`
...
LL | asm!("{a}", a = const foo, a = const bar);
| ^^^ non-constant value
error[E0435]: attempt to use a non-constant value in a constant
--> $DIR/parse-error.rs:47:46
|
LL | let mut bar = 0;
| ---------- help: consider using `const` instead of `let`: `const bar`
...
LL | asm!("{a}", in("eax") foo, a = const bar);
| ^^^ non-constant value
error[E0435]: attempt to use a non-constant value in a constant
--> $DIR/parse-error.rs:50:46
|
LL | let mut bar = 0;
| ---------- help: consider using `const` instead of `let`: `const bar`
...
LL | asm!("{a}", in("eax") foo, a = const bar);
| ^^^ non-constant value
error[E0435]: attempt to use a non-constant value in a constant
--> $DIR/parse-error.rs:53:42
|
LL | let mut bar = 0;
| ---------- help: consider using `const` instead of `let`: `const bar`
...
LL | asm!("{1}", in("eax") foo, const bar);
| ^^^ non-constant value
error: aborting due to 31 previous errors
For more information about this error, try `rustc --explain E0435`.

View file

@ -21,5 +21,23 @@ fn main() {
//~^ ERROR the size for values of type `[u64]` cannot be known at compilation time //~^ ERROR the size for values of type `[u64]` cannot be known at compilation time
asm!("{}", inout(reg) v[..]); asm!("{}", inout(reg) v[..]);
//~^ ERROR the size for values of type `[u64]` cannot be known at compilation time //~^ ERROR the size for values of type `[u64]` cannot be known at compilation time
// Constants must be... constant
let x = 0;
const fn const_foo(x: i32) -> i32 {
x
}
const fn const_bar<T>(x: T) -> T {
x
}
asm!("{}", const x);
//~^ ERROR attempt to use a non-constant value in a constant
asm!("{}", const const_foo(0));
asm!("{}", const const_foo(x));
//~^ ERROR attempt to use a non-constant value in a constant
asm!("{}", const const_bar(0));
asm!("{}", const const_bar(x));
//~^ ERROR attempt to use a non-constant value in a constant
} }
} }

View file

@ -1,3 +1,30 @@
error[E0435]: attempt to use a non-constant value in a constant
--> $DIR/type-check-1.rs:34:26
|
LL | let x = 0;
| ----- help: consider using `const` instead of `let`: `const x`
...
LL | asm!("{}", const x);
| ^ non-constant value
error[E0435]: attempt to use a non-constant value in a constant
--> $DIR/type-check-1.rs:37:36
|
LL | let x = 0;
| ----- help: consider using `const` instead of `let`: `const x`
...
LL | asm!("{}", const const_foo(x));
| ^ non-constant value
error[E0435]: attempt to use a non-constant value in a constant
--> $DIR/type-check-1.rs:40:36
|
LL | let x = 0;
| ----- help: consider using `const` instead of `let`: `const x`
...
LL | asm!("{}", const const_bar(x));
| ^ non-constant value
error: invalid asm output error: invalid asm output
--> $DIR/type-check-1.rs:10:29 --> $DIR/type-check-1.rs:10:29
| |
@ -37,6 +64,7 @@ LL | asm!("{}", inout(reg) v[..]);
= help: the trait `Sized` is not implemented for `[u64]` = help: the trait `Sized` is not implemented for `[u64]`
= note: all inline asm arguments must have a statically known size = note: all inline asm arguments must have a statically known size
error: aborting due to 5 previous errors error: aborting due to 8 previous errors
For more information about this error, try `rustc --explain E0277`. Some errors have detailed explanations: E0277, E0435.
For more information about an error, try `rustc --explain E0277`.

View file

@ -28,31 +28,19 @@ fn main() {
// Const operands must be integer or floats, and must be constants. // Const operands must be integer or floats, and must be constants.
let x = 0; asm!("{}", const 0);
const C: i32 = 0;
const fn const_foo(x: i32) -> i32 {
x
}
const fn const_bar<T>(x: T) -> T {
x
}
asm!("{}", const 0i32); asm!("{}", const 0i32);
asm!("{}", const 0f32); asm!("{}", const 0f32);
asm!("{}", const 0 as *mut u8); asm!("{}", const 0 as *mut u8);
//~^ ERROR asm `const` arguments must be integer or floating-point values //~^ ERROR asm `const` arguments must be integer or floating-point values
asm!("{}", const &0);
//~^ ERROR asm `const` arguments must be integer or floating-point values // This currently causes an ICE: https://github.com/rust-lang/rust/issues/81857
asm!("{}", const x); // asm!("{}", const &0);
//~^ ERROR argument 1 is required to be a constant // ERROR asm `const` arguments must be integer or floating-point values
asm!("{}", const const_foo(0));
asm!("{}", const const_foo(x));
//~^ ERROR argument 1 is required to be a constant
asm!("{}", const const_bar(0));
asm!("{}", const const_bar(x));
//~^ ERROR argument 1 is required to be a constant
// Sym operands must point to a function or static // Sym operands must point to a function or static
const C: i32 = 0;
static S: i32 = 0; static S: i32 = 0;
asm!("{}", sym S); asm!("{}", sym S);
asm!("{}", sym main); asm!("{}", sym main);

View file

@ -1,25 +1,19 @@
error: asm `const` arguments must be integer or floating-point values error: asm `const` arguments must be integer or floating-point values
--> $DIR/type-check-2.rs:41:26 --> $DIR/type-check-2.rs:34:20
| |
LL | asm!("{}", const 0 as *mut u8); LL | asm!("{}", const 0 as *mut u8);
| ^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^
error: asm `const` arguments must be integer or floating-point values
--> $DIR/type-check-2.rs:43:26
|
LL | asm!("{}", const &0);
| ^^
error: arguments for inline assembly must be copyable error: arguments for inline assembly must be copyable
--> $DIR/type-check-2.rs:66:32 --> $DIR/type-check-2.rs:54:32
| |
LL | asm!("{}", in(xmm_reg) SimdNonCopy(0.0, 0.0, 0.0, 0.0)); LL | asm!("{}", in(xmm_reg) SimdNonCopy(0.0, 0.0, 0.0, 0.0));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| |
= note: `SimdNonCopy` does not implement the Copy trait = note: `SimdNonCopy` does not implement the Copy trait
error: cannot use value of type `[closure@$DIR/type-check-2.rs:78:28: 78:38]` for inline assembly error: cannot use value of type `[closure@$DIR/type-check-2.rs:66:28: 66:38]` for inline assembly
--> $DIR/type-check-2.rs:78:28 --> $DIR/type-check-2.rs:66:28
| |
LL | asm!("{}", in(reg) |x: i32| x); LL | asm!("{}", in(reg) |x: i32| x);
| ^^^^^^^^^^ | ^^^^^^^^^^
@ -27,7 +21,7 @@ LL | asm!("{}", in(reg) |x: i32| x);
= note: only integers, floats, SIMD vectors, pointers and function pointers can be used as arguments for inline assembly = note: only integers, floats, SIMD vectors, pointers and function pointers can be used as arguments for inline assembly
error: cannot use value of type `Vec<i32>` for inline assembly error: cannot use value of type `Vec<i32>` for inline assembly
--> $DIR/type-check-2.rs:80:28 --> $DIR/type-check-2.rs:68:28
| |
LL | asm!("{}", in(reg) vec![0]); LL | asm!("{}", in(reg) vec![0]);
| ^^^^^^^ | ^^^^^^^
@ -36,7 +30,7 @@ LL | asm!("{}", in(reg) vec![0]);
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
error: cannot use value of type `(i32, i32, i32)` for inline assembly error: cannot use value of type `(i32, i32, i32)` for inline assembly
--> $DIR/type-check-2.rs:82:28 --> $DIR/type-check-2.rs:70:28
| |
LL | asm!("{}", in(reg) (1, 2, 3)); LL | asm!("{}", in(reg) (1, 2, 3));
| ^^^^^^^^^ | ^^^^^^^^^
@ -44,7 +38,7 @@ LL | asm!("{}", in(reg) (1, 2, 3));
= note: only integers, floats, SIMD vectors, pointers and function pointers can be used as arguments for inline assembly = note: only integers, floats, SIMD vectors, pointers and function pointers can be used as arguments for inline assembly
error: cannot use value of type `[i32; 3]` for inline assembly error: cannot use value of type `[i32; 3]` for inline assembly
--> $DIR/type-check-2.rs:84:28 --> $DIR/type-check-2.rs:72:28
| |
LL | asm!("{}", in(reg) [1, 2, 3]); LL | asm!("{}", in(reg) [1, 2, 3]);
| ^^^^^^^^^ | ^^^^^^^^^
@ -52,7 +46,7 @@ LL | asm!("{}", in(reg) [1, 2, 3]);
= note: only integers, floats, SIMD vectors, pointers and function pointers can be used as arguments for inline assembly = note: only integers, floats, SIMD vectors, pointers and function pointers can be used as arguments for inline assembly
error: cannot use value of type `fn() {main}` for inline assembly error: cannot use value of type `fn() {main}` for inline assembly
--> $DIR/type-check-2.rs:92:31 --> $DIR/type-check-2.rs:80:31
| |
LL | asm!("{}", inout(reg) f); LL | asm!("{}", inout(reg) f);
| ^ | ^
@ -60,7 +54,7 @@ LL | asm!("{}", inout(reg) f);
= note: only integers, floats, SIMD vectors, pointers and function pointers can be used as arguments for inline assembly = note: only integers, floats, SIMD vectors, pointers and function pointers can be used as arguments for inline assembly
error: cannot use value of type `&mut i32` for inline assembly error: cannot use value of type `&mut i32` for inline assembly
--> $DIR/type-check-2.rs:95:31 --> $DIR/type-check-2.rs:83:31
| |
LL | asm!("{}", inout(reg) r); LL | asm!("{}", inout(reg) r);
| ^ | ^
@ -68,35 +62,17 @@ LL | asm!("{}", inout(reg) r);
= note: only integers, floats, SIMD vectors, pointers and function pointers can be used as arguments for inline assembly = note: only integers, floats, SIMD vectors, pointers and function pointers can be used as arguments for inline assembly
error: asm `sym` operand must point to a fn or static error: asm `sym` operand must point to a fn or static
--> $DIR/type-check-2.rs:59:24 --> $DIR/type-check-2.rs:47:24
| |
LL | asm!("{}", sym C); LL | asm!("{}", sym C);
| ^ | ^
error: asm `sym` operand must point to a fn or static error: asm `sym` operand must point to a fn or static
--> $DIR/type-check-2.rs:61:24 --> $DIR/type-check-2.rs:49:24
| |
LL | asm!("{}", sym x); LL | asm!("{}", sym x);
| ^ | ^
error: argument 1 is required to be a constant
--> $DIR/type-check-2.rs:45:9
|
LL | asm!("{}", const x);
| ^^^^^^^^^^^^^^^^^^^^
error: argument 1 is required to be a constant
--> $DIR/type-check-2.rs:48:9
|
LL | asm!("{}", const const_foo(x));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: argument 1 is required to be a constant
--> $DIR/type-check-2.rs:51:9
|
LL | asm!("{}", const const_bar(x));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0381]: use of possibly-uninitialized variable: `x` error[E0381]: use of possibly-uninitialized variable: `x`
--> $DIR/type-check-2.rs:13:28 --> $DIR/type-check-2.rs:13:28
| |
@ -127,7 +103,7 @@ LL | let v: Vec<u64> = vec![0, 1, 2];
LL | asm!("{}", inout(reg) v[0]); LL | asm!("{}", inout(reg) v[0]);
| ^ cannot borrow as mutable | ^ cannot borrow as mutable
error: aborting due to 18 previous errors error: aborting due to 14 previous errors
Some errors have detailed explanations: E0381, E0596. Some errors have detailed explanations: E0381, E0596.
For more information about an error, try `rustc --explain E0381`. For more information about an error, try `rustc --explain E0381`.

View file

@ -142,12 +142,12 @@ fn never_loop_expr(expr: &Expr<'_>, main_loop_id: HirId) -> NeverLoopResult {
.map(|(o, _)| match o { .map(|(o, _)| match o {
InlineAsmOperand::In { expr, .. } InlineAsmOperand::In { expr, .. }
| InlineAsmOperand::InOut { expr, .. } | InlineAsmOperand::InOut { expr, .. }
| InlineAsmOperand::Const { expr }
| InlineAsmOperand::Sym { expr } => never_loop_expr(expr, main_loop_id), | InlineAsmOperand::Sym { expr } => never_loop_expr(expr, main_loop_id),
InlineAsmOperand::Out { expr, .. } => never_loop_expr_all(&mut expr.iter(), main_loop_id), InlineAsmOperand::Out { expr, .. } => never_loop_expr_all(&mut expr.iter(), main_loop_id),
InlineAsmOperand::SplitInOut { in_expr, out_expr, .. } => { InlineAsmOperand::SplitInOut { in_expr, out_expr, .. } => {
never_loop_expr_all(&mut once(in_expr).chain(out_expr.iter()), main_loop_id) never_loop_expr_all(&mut once(in_expr).chain(out_expr.iter()), main_loop_id)
}, },
InlineAsmOperand::Const { .. } => NeverLoopResult::Otherwise,
}) })
.fold(NeverLoopResult::Otherwise, combine_both), .fold(NeverLoopResult::Otherwise, combine_both),
ExprKind::Struct(_, _, None) ExprKind::Struct(_, _, None)

View file

@ -306,7 +306,6 @@ fn print_expr(cx: &LateContext<'_>, expr: &hir::Expr<'_>, indent: usize) {
match op { match op {
hir::InlineAsmOperand::In { expr, .. } hir::InlineAsmOperand::In { expr, .. }
| hir::InlineAsmOperand::InOut { expr, .. } | hir::InlineAsmOperand::InOut { expr, .. }
| hir::InlineAsmOperand::Const { expr }
| hir::InlineAsmOperand::Sym { expr } => print_expr(cx, expr, indent + 1), | hir::InlineAsmOperand::Sym { expr } => print_expr(cx, expr, indent + 1),
hir::InlineAsmOperand::Out { expr, .. } => { hir::InlineAsmOperand::Out { expr, .. } => {
if let Some(expr) = expr { if let Some(expr) = expr {
@ -319,6 +318,10 @@ fn print_expr(cx: &LateContext<'_>, expr: &hir::Expr<'_>, indent: usize) {
print_expr(cx, out_expr, indent + 1); print_expr(cx, out_expr, indent + 1);
} }
}, },
hir::InlineAsmOperand::Const { anon_const } => {
println!("{}anon_const:", ind);
print_expr(cx, &cx.tcx.hir().body(anon_const.body).value, indent + 1);
}
} }
} }
}, },

View file

@ -663,7 +663,8 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> {
self.hash_expr(out_expr); self.hash_expr(out_expr);
} }
}, },
InlineAsmOperand::Const { expr } | InlineAsmOperand::Sym { expr } => self.hash_expr(expr), InlineAsmOperand::Const { anon_const } => self.hash_body(anon_const.body),
InlineAsmOperand::Sym { expr } => self.hash_expr(expr),
} }
} }
}, },