@@ -27,20 +27,19 @@ enum NonAsmTypeReason<'tcx> {
27
27
UnevaluatedSIMDArrayLength ( DefId , ty:: Const < ' tcx > ) ,
28
28
Invalid ( Ty < ' tcx > ) ,
29
29
InvalidElement ( DefId , Ty < ' tcx > ) ,
30
+ NotSizedPtr ( Ty < ' tcx > ) ,
30
31
}
31
32
32
33
impl < ' a , ' tcx > InlineAsmCtxt < ' a , ' tcx > {
33
34
pub fn new (
34
35
tcx : TyCtxt < ' tcx > ,
35
36
def_id : LocalDefId ,
37
+ typing_env : ty:: TypingEnv < ' tcx > ,
36
38
get_operand_ty : impl Fn ( & hir:: Expr < ' tcx > ) -> Ty < ' tcx > + ' a ,
37
39
) -> Self {
38
40
InlineAsmCtxt {
39
41
tcx,
40
- typing_env : ty:: TypingEnv {
41
- typing_mode : ty:: TypingMode :: non_body_analysis ( ) ,
42
- param_env : ty:: ParamEnv :: empty ( ) ,
43
- } ,
42
+ typing_env,
44
43
target_features : tcx. asm_target_features ( def_id) ,
45
44
expr_ty : Box :: new ( get_operand_ty) ,
46
45
}
@@ -83,7 +82,13 @@ impl<'a, 'tcx> InlineAsmCtxt<'a, 'tcx> {
83
82
ty:: Float ( FloatTy :: F64 ) => Ok ( InlineAsmType :: F64 ) ,
84
83
ty:: Float ( FloatTy :: F128 ) => Ok ( InlineAsmType :: F128 ) ,
85
84
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
+ }
87
92
ty:: Adt ( adt, args) if adt. repr ( ) . simd ( ) => {
88
93
let fields = & adt. non_enum_variant ( ) . fields ;
89
94
let field = & fields[ FieldIdx :: ZERO ] ;
@@ -189,6 +194,16 @@ impl<'a, 'tcx> InlineAsmCtxt<'a, 'tcx> {
189
194
can be used as arguments for inline assembly",
190
195
) . emit ( ) ;
191
196
}
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
+ }
192
207
NonAsmTypeReason :: InvalidElement ( did, ty) => {
193
208
let msg = format ! (
194
209
"cannot use SIMD vector with element type `{ty}` for inline assembly"
0 commit comments