@@ -18,7 +18,8 @@ use self::utils::{DIB, span_start, assert_type_for_node_id, contains_nodebug_att
18
18
create_DIArray, is_node_local_to_unit} ;
19
19
use self :: namespace:: { namespace_for_item, NamespaceTreeNode } ;
20
20
use self :: type_names:: compute_debuginfo_type_name;
21
- use self :: metadata:: { type_metadata, file_metadata, scope_metadata, TypeMap , compile_unit_metadata} ;
21
+ use self :: metadata:: { type_metadata, diverging_type_metadata} ;
22
+ use self :: metadata:: { file_metadata, scope_metadata, TypeMap , compile_unit_metadata} ;
22
23
use self :: source_loc:: InternalDebugLocation ;
23
24
24
25
use llvm;
@@ -29,8 +30,8 @@ use middle::subst::{self, Substs};
29
30
use rustc:: ast_map;
30
31
use trans:: common:: { NodeIdAndSpan , CrateContext , FunctionContext , Block } ;
31
32
use trans;
32
- use trans:: monomorphize;
33
- use middle:: ty:: Ty ;
33
+ use trans:: { monomorphize, type_of } ;
34
+ use middle:: ty:: { self , Ty } ;
34
35
use session:: config:: { self , FullDebugInfo , LimitedDebugInfo , NoDebugInfo } ;
35
36
use util:: nodemap:: { NodeMap , FnvHashMap , FnvHashSet } ;
36
37
@@ -40,7 +41,7 @@ use std::ffi::CString;
40
41
use std:: ptr;
41
42
use std:: rc:: Rc ;
42
43
use syntax:: codemap:: { Span , Pos } ;
43
- use syntax:: { ast, codemap, ast_util} ;
44
+ use syntax:: { abi , ast, codemap, ast_util} ;
44
45
use syntax:: attr:: IntType ;
45
46
use syntax:: parse:: token:: { self , special_idents} ;
46
47
@@ -325,7 +326,6 @@ pub fn create_function_debug_context<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
325
326
let function_type_metadata = unsafe {
326
327
let fn_signature = get_function_signature ( cx,
327
328
fn_ast_id,
328
- & * fn_decl,
329
329
param_substs,
330
330
span) ;
331
331
llvm:: LLVMDIBuilderCreateSubroutineType ( DIB ( cx) , file_metadata, fn_signature)
@@ -402,35 +402,49 @@ pub fn create_function_debug_context<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
402
402
403
403
fn get_function_signature < ' a , ' tcx > ( cx : & CrateContext < ' a , ' tcx > ,
404
404
fn_ast_id : ast:: NodeId ,
405
- fn_decl : & ast:: FnDecl ,
406
405
param_substs : & Substs < ' tcx > ,
407
406
error_reporting_span : Span ) -> DIArray {
408
407
if cx. sess ( ) . opts . debuginfo == LimitedDebugInfo {
409
408
return create_DIArray ( DIB ( cx) , & [ ] ) ;
410
409
}
411
410
412
- let mut signature = Vec :: with_capacity ( fn_decl. inputs . len ( ) + 1 ) ;
413
-
414
411
// Return type -- llvm::DIBuilder wants this at index 0
415
412
assert_type_for_node_id ( cx, fn_ast_id, error_reporting_span) ;
416
- let return_type = cx. tcx ( ) . node_id_to_type ( fn_ast_id) ;
417
- let return_type = monomorphize:: apply_param_substs ( cx. tcx ( ) ,
418
- param_substs,
419
- & return_type) ;
420
- if return_type. is_nil ( ) {
421
- signature. push ( ptr:: null_mut ( ) )
413
+ let fn_type = cx. tcx ( ) . node_id_to_type ( fn_ast_id) ;
414
+
415
+ let ( sig, abi) = match fn_type. sty {
416
+ ty:: TyBareFn ( _, ref barefnty) => {
417
+ ( cx. tcx ( ) . erase_late_bound_regions ( & barefnty. sig ) , barefnty. abi )
418
+ }
419
+ ty:: TyClosure ( def_id, substs) => {
420
+ let closure_type = cx. tcx ( ) . closure_type ( def_id, substs) ;
421
+ ( cx. tcx ( ) . erase_late_bound_regions ( & closure_type. sig ) , closure_type. abi )
422
+ }
423
+
424
+ _ => cx. sess ( ) . bug ( "get_function_metdata: Expected a function type!" )
425
+ } ;
426
+ let sig = monomorphize:: apply_param_substs ( cx. tcx ( ) , param_substs, & sig) ;
427
+
428
+ let mut signature = Vec :: with_capacity ( sig. inputs . len ( ) + 1 ) ;
429
+
430
+ // Return type -- llvm::DIBuilder wants this at index 0
431
+ signature. push ( match sig. output {
432
+ ty:: FnConverging ( ret_ty) => match ret_ty. sty {
433
+ ty:: TyTuple ( ref tys) if tys. is_empty ( ) => ptr:: null_mut ( ) ,
434
+ _ => type_metadata ( cx, ret_ty, codemap:: DUMMY_SP )
435
+ } ,
436
+ ty:: FnDiverging => diverging_type_metadata ( cx)
437
+ } ) ;
438
+
439
+ let inputs = & if abi == abi:: RustCall {
440
+ type_of:: untuple_arguments ( cx, & sig. inputs )
422
441
} else {
423
- signature . push ( type_metadata ( cx , return_type , codemap :: DUMMY_SP ) ) ;
424
- }
442
+ sig . inputs
443
+ } ;
425
444
426
445
// Arguments types
427
- for arg in & fn_decl. inputs {
428
- assert_type_for_node_id ( cx, arg. pat . id , arg. pat . span ) ;
429
- let arg_type = cx. tcx ( ) . node_id_to_type ( arg. pat . id ) ;
430
- let arg_type = monomorphize:: apply_param_substs ( cx. tcx ( ) ,
431
- param_substs,
432
- & arg_type) ;
433
- signature. push ( type_metadata ( cx, arg_type, codemap:: DUMMY_SP ) ) ;
446
+ for & argument_type in inputs {
447
+ signature. push ( type_metadata ( cx, argument_type, codemap:: DUMMY_SP ) ) ;
434
448
}
435
449
436
450
return create_DIArray ( DIB ( cx) , & signature[ ..] ) ;
0 commit comments