@@ -4,9 +4,10 @@ use rustc_middle::mir::mono::{Linkage, MonoItem, MonoItemData, Visibility};
4
4
use rustc_middle:: mir:: { Body , InlineAsmOperand } ;
5
5
use rustc_middle:: ty:: layout:: { FnAbiOf , HasTyCtxt , HasTypingEnv , LayoutOf } ;
6
6
use rustc_middle:: ty:: { Instance , Ty , TyCtxt } ;
7
- use rustc_middle:: { bug, ty} ;
8
- use rustc_span:: sym;
7
+ use rustc_middle:: { bug, span_bug , ty} ;
8
+ use rustc_span:: { Span , sym} ;
9
9
use rustc_target:: callconv:: { ArgAbi , FnAbi , PassMode } ;
10
+ use rustc_target:: spec:: WasmCAbi ;
10
11
11
12
use crate :: common;
12
13
use crate :: traits:: { AsmCodegenMethods , BuilderMethods , GlobalAsmOperandRef , MiscCodegenMethods } ;
@@ -285,7 +286,12 @@ fn prefix_and_suffix<'tcx>(
285
286
writeln ! ( begin, "{}" , arch_prefix) . unwrap ( ) ;
286
287
}
287
288
writeln ! ( begin, "{asm_name}:" ) . unwrap ( ) ;
288
- writeln ! ( begin, ".functype {asm_name} {}" , wasm_functype( tcx, fn_abi) ) . unwrap ( ) ;
289
+ writeln ! (
290
+ begin,
291
+ ".functype {asm_name} {}" ,
292
+ wasm_functype( tcx, fn_abi, tcx. def_span( instance. def_id( ) ) )
293
+ )
294
+ . unwrap ( ) ;
289
295
290
296
writeln ! ( end) . unwrap ( ) ;
291
297
// .size is ignored for function symbols, so we can skip it
@@ -299,7 +305,7 @@ fn prefix_and_suffix<'tcx>(
299
305
/// The webassembly type signature for the given function.
300
306
///
301
307
/// Used by the `.functype` directive on wasm targets.
302
- fn wasm_functype < ' tcx > ( tcx : TyCtxt < ' tcx > , fn_abi : & FnAbi < ' tcx , Ty < ' tcx > > ) -> String {
308
+ fn wasm_functype < ' tcx > ( tcx : TyCtxt < ' tcx > , fn_abi : & FnAbi < ' tcx , Ty < ' tcx > > , span : Span ) -> String {
303
309
let mut signature = String :: with_capacity ( 64 ) ;
304
310
305
311
let ptr_type = match tcx. data_layout . pointer_size . bits ( ) {
@@ -308,8 +314,18 @@ fn wasm_functype<'tcx>(tcx: TyCtxt<'tcx>, fn_abi: &FnAbi<'tcx, Ty<'tcx>>) -> Str
308
314
other => bug ! ( "wasm pointer size cannot be {other} bits" ) ,
309
315
} ;
310
316
311
- let hidden_return =
312
- matches ! ( fn_abi. ret. mode, PassMode :: Indirect { .. } | PassMode :: Pair { .. } ) ;
317
+ // FIXME: remove this once the wasm32-unknown-unknown ABI is fixed
318
+ // please also add `wasm32-unknown-unknown` back in `tests/assembly/wasm32-naked-fn.rs`
319
+ // basically the commit introducing this comment should be reverted
320
+ if let PassMode :: Pair { .. } = fn_abi. ret . mode {
321
+ let _ = WasmCAbi :: Legacy ;
322
+ span_bug ! (
323
+ span,
324
+ "cannot return a pair (the wasm32-unknown-unknown ABI is broken, see https://github.com/rust-lang/rust/issues/115666"
325
+ ) ;
326
+ }
327
+
328
+ let hidden_return = matches ! ( fn_abi. ret. mode, PassMode :: Indirect { .. } ) ;
313
329
314
330
signature. push ( '(' ) ;
315
331
@@ -322,7 +338,7 @@ fn wasm_functype<'tcx>(tcx: TyCtxt<'tcx>, fn_abi: &FnAbi<'tcx, Ty<'tcx>>) -> Str
322
338
323
339
let mut it = fn_abi. args . iter ( ) . peekable ( ) ;
324
340
while let Some ( arg_abi) = it. next ( ) {
325
- wasm_type ( & mut signature, arg_abi, ptr_type) ;
341
+ wasm_type ( & mut signature, arg_abi, ptr_type, span ) ;
326
342
if it. peek ( ) . is_some ( ) {
327
343
signature. push_str ( ", " ) ;
328
344
}
@@ -331,21 +347,34 @@ fn wasm_functype<'tcx>(tcx: TyCtxt<'tcx>, fn_abi: &FnAbi<'tcx, Ty<'tcx>>) -> Str
331
347
signature. push_str ( ") -> (" ) ;
332
348
333
349
if !hidden_return {
334
- wasm_type ( & mut signature, & fn_abi. ret , ptr_type) ;
350
+ wasm_type ( & mut signature, & fn_abi. ret , ptr_type, span ) ;
335
351
}
336
352
337
353
signature. push ( ')' ) ;
338
354
339
355
signature
340
356
}
341
357
342
- fn wasm_type < ' tcx > ( signature : & mut String , arg_abi : & ArgAbi < ' _ , Ty < ' tcx > > , ptr_type : & ' static str ) {
358
+ fn wasm_type < ' tcx > (
359
+ signature : & mut String ,
360
+ arg_abi : & ArgAbi < ' _ , Ty < ' tcx > > ,
361
+ ptr_type : & ' static str ,
362
+ span : Span ,
363
+ ) {
343
364
match arg_abi. mode {
344
365
PassMode :: Ignore => { /* do nothing */ }
345
366
PassMode :: Direct ( _) => {
346
367
let direct_type = match arg_abi. layout . backend_repr {
347
368
BackendRepr :: Scalar ( scalar) => wasm_primitive ( scalar. primitive ( ) , ptr_type) ,
348
369
BackendRepr :: Vector { .. } => "v128" ,
370
+ BackendRepr :: Memory { .. } => {
371
+ // FIXME: remove this branch once the wasm32-unknown-unknown ABI is fixed
372
+ let _ = WasmCAbi :: Legacy ;
373
+ span_bug ! (
374
+ span,
375
+ "cannot use memory args (the wasm32-unknown-unknown ABI is broken, see https://github.com/rust-lang/rust/issues/115666"
376
+ ) ;
377
+ }
349
378
other => unreachable ! ( "unexpected BackendRepr: {:?}" , other) ,
350
379
} ;
351
380
0 commit comments