@@ -11,24 +11,24 @@ use rustc_target::asm::{InlineAsmReg, InlineAsmRegClass, InlineAsmRegOrRegClass,
11
11
pub struct InlineAsmCtxt < ' a , ' tcx > {
12
12
tcx : TyCtxt < ' tcx > ,
13
13
param_env : ty:: ParamEnv < ' tcx > ,
14
- get_operand_ty : Box < dyn Fn ( & ' tcx hir:: Expr < ' tcx > ) -> Ty < ' tcx > + ' a > ,
14
+ get_expr_ty : Box < dyn Fn ( & ' tcx hir:: Expr < ' tcx > ) -> Ty < ' tcx > + ' a > ,
15
15
}
16
16
17
17
impl < ' a , ' tcx > InlineAsmCtxt < ' a , ' tcx > {
18
18
pub fn new_global_asm ( tcx : TyCtxt < ' tcx > ) -> Self {
19
19
InlineAsmCtxt {
20
20
tcx,
21
21
param_env : ty:: ParamEnv :: empty ( ) ,
22
- get_operand_ty : Box :: new ( |e| bug ! ( "asm operand in global asm: {e:?}" ) ) ,
22
+ get_expr_ty : Box :: new ( |e| bug ! ( "asm operand in global asm: {e:?}" ) ) ,
23
23
}
24
24
}
25
25
26
26
pub fn new_in_fn (
27
27
tcx : TyCtxt < ' tcx > ,
28
28
param_env : ty:: ParamEnv < ' tcx > ,
29
- get_operand_ty : impl Fn ( & ' tcx hir:: Expr < ' tcx > ) -> Ty < ' tcx > + ' a ,
29
+ get_expr_ty : impl Fn ( & ' tcx hir:: Expr < ' tcx > ) -> Ty < ' tcx > + ' a ,
30
30
) -> Self {
31
- InlineAsmCtxt { tcx, param_env, get_operand_ty : Box :: new ( get_operand_ty ) }
31
+ InlineAsmCtxt { tcx, param_env, get_expr_ty : Box :: new ( get_expr_ty ) }
32
32
}
33
33
34
34
// FIXME(compiler-errors): This could use `<$ty as Pointee>::Metadata == ()`
@@ -124,7 +124,7 @@ impl<'a, 'tcx> InlineAsmCtxt<'a, 'tcx> {
124
124
tied_input : Option < ( & ' tcx hir:: Expr < ' tcx > , Option < InlineAsmType > ) > ,
125
125
target_features : & FxIndexSet < Symbol > ,
126
126
) -> Option < InlineAsmType > {
127
- let ty = ( self . get_operand_ty ) ( expr) ;
127
+ let ty = ( self . get_expr_ty ) ( expr) ;
128
128
if ty. has_non_region_infer ( ) {
129
129
bug ! ( "inference variable in asm operand ty: {:?} {:?}" , expr, ty) ;
130
130
}
@@ -178,7 +178,7 @@ impl<'a, 'tcx> InlineAsmCtxt<'a, 'tcx> {
178
178
let msg = "incompatible types for asm inout argument" ;
179
179
let mut err = self . tcx . sess . struct_span_err ( vec ! [ in_expr. span, expr. span] , msg) ;
180
180
181
- let in_expr_ty = ( self . get_operand_ty ) ( in_expr) ;
181
+ let in_expr_ty = ( self . get_expr_ty ) ( in_expr) ;
182
182
err. span_label ( in_expr. span , format ! ( "type `{in_expr_ty}`" ) ) ;
183
183
err. span_label ( expr. span , format ! ( "type `{ty}`" ) ) ;
184
184
err. note (
@@ -437,7 +437,7 @@ impl<'a, 'tcx> InlineAsmCtxt<'a, 'tcx> {
437
437
hir:: InlineAsmOperand :: Const { .. } | hir:: InlineAsmOperand :: SymStatic { .. } => { }
438
438
// Check that sym actually points to a function. Later passes
439
439
// depend on this.
440
- hir:: InlineAsmOperand :: SymFn { anon_const } => {
440
+ hir:: InlineAsmOperand :: SymFnInGlobal { anon_const } => {
441
441
let ty = self . tcx . type_of ( anon_const. def_id ) . instantiate_identity ( ) ;
442
442
match ty. kind ( ) {
443
443
ty:: Never | ty:: Error ( _) => { }
@@ -454,6 +454,23 @@ impl<'a, 'tcx> InlineAsmCtxt<'a, 'tcx> {
454
454
}
455
455
} ;
456
456
}
457
+ hir:: InlineAsmOperand :: SymFnInInline { expr } => {
458
+ let ty = ( self . get_expr_ty ) ( expr) ;
459
+ match ty. kind ( ) {
460
+ ty:: Never | ty:: Error ( _) => { }
461
+ ty:: FnDef ( ..) => { }
462
+ _ => {
463
+ let mut err =
464
+ self . tcx . sess . struct_span_err ( * op_sp, "invalid `sym` operand" ) ;
465
+ err. span_label (
466
+ expr. span ,
467
+ format ! ( "is {} `{}`" , ty. kind( ) . article( ) , ty) ,
468
+ ) ;
469
+ err. help ( "`sym` operands must refer to either a function or a static" ) ;
470
+ err. emit ( ) ;
471
+ }
472
+ } ;
473
+ }
457
474
}
458
475
}
459
476
}
0 commit comments