@@ -27,20 +27,19 @@ enum NonAsmTypeReason<'tcx> {
2727 UnevaluatedSIMDArrayLength ( DefId , ty:: Const < ' tcx > ) ,
2828 Invalid ( Ty < ' tcx > ) ,
2929 InvalidElement ( DefId , Ty < ' tcx > ) ,
30+ NotSizedPtr ( Ty < ' tcx > ) ,
3031}
3132
3233impl < ' a , ' tcx > InlineAsmCtxt < ' a , ' tcx > {
3334 pub fn new (
3435 tcx : TyCtxt < ' tcx > ,
3536 def_id : LocalDefId ,
37+ typing_env : ty:: TypingEnv < ' tcx > ,
3638 get_operand_ty : impl Fn ( & hir:: Expr < ' tcx > ) -> Ty < ' tcx > + ' a ,
3739 ) -> Self {
3840 InlineAsmCtxt {
3941 tcx,
40- typing_env : ty:: TypingEnv {
41- typing_mode : ty:: TypingMode :: non_body_analysis ( ) ,
42- param_env : ty:: ParamEnv :: empty ( ) ,
43- } ,
42+ typing_env,
4443 target_features : tcx. asm_target_features ( def_id) ,
4544 expr_ty : Box :: new ( get_operand_ty) ,
4645 }
@@ -83,7 +82,13 @@ impl<'a, 'tcx> InlineAsmCtxt<'a, 'tcx> {
8382 ty:: Float ( FloatTy :: F64 ) => Ok ( InlineAsmType :: F64 ) ,
8483 ty:: Float ( FloatTy :: F128 ) => Ok ( InlineAsmType :: F128 ) ,
8584 ty:: FnPtr ( ..) => Ok ( asm_ty_isize) ,
86- ty:: RawPtr ( ty, _) if self . is_thin_ptr_ty ( ty) => Ok ( asm_ty_isize) ,
85+ ty:: RawPtr ( elem_ty, _) => {
86+ if self . is_thin_ptr_ty ( elem_ty) {
87+ Ok ( asm_ty_isize)
88+ } else {
89+ Err ( NonAsmTypeReason :: NotSizedPtr ( ty) )
90+ }
91+ }
8792 ty:: Adt ( adt, args) if adt. repr ( ) . simd ( ) => {
8893 let fields = & adt. non_enum_variant ( ) . fields ;
8994 let field = & fields[ FieldIdx :: ZERO ] ;
@@ -189,6 +194,16 @@ impl<'a, 'tcx> InlineAsmCtxt<'a, 'tcx> {
189194 can be used as arguments for inline assembly",
190195 ) . emit ( ) ;
191196 }
197+ NonAsmTypeReason :: NotSizedPtr ( ty) => {
198+ let msg = format ! (
199+ "cannot use value of unsized pointer type `{ty}` for inline assembly"
200+ ) ;
201+ self . tcx
202+ . dcx ( )
203+ . struct_span_err ( expr. span , msg)
204+ . with_note ( "only sized pointers can be used in inline assembly" )
205+ . emit ( ) ;
206+ }
192207 NonAsmTypeReason :: InvalidElement ( did, ty) => {
193208 let msg = format ! (
194209 "cannot use SIMD vector with element type `{ty}` for inline assembly"
0 commit comments