@@ -18,7 +18,8 @@ use self::utils::{DIB, span_start, assert_type_for_node_id, contains_nodebug_att
1818 create_DIArray, is_node_local_to_unit} ;
1919use self :: namespace:: { namespace_for_item, NamespaceTreeNode } ;
2020use 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} ;
2223use self :: source_loc:: InternalDebugLocation ;
2324
2425use llvm;
@@ -29,8 +30,8 @@ use middle::subst::{self, Substs};
2930use rustc:: ast_map;
3031use trans:: common:: { NodeIdAndSpan , CrateContext , FunctionContext , Block } ;
3132use trans;
32- use trans:: monomorphize;
33- use middle:: ty:: Ty ;
33+ use trans:: { monomorphize, type_of } ;
34+ use middle:: ty:: { self , Ty } ;
3435use session:: config:: { self , FullDebugInfo , LimitedDebugInfo , NoDebugInfo } ;
3536use util:: nodemap:: { NodeMap , FnvHashMap , FnvHashSet } ;
3637
@@ -40,7 +41,7 @@ use std::ffi::CString;
4041use std:: ptr;
4142use std:: rc:: Rc ;
4243use syntax:: codemap:: { Span , Pos } ;
43- use syntax:: { ast, codemap, ast_util} ;
44+ use syntax:: { abi , ast, codemap, ast_util} ;
4445use syntax:: attr:: IntType ;
4546use syntax:: parse:: token:: { self , special_idents} ;
4647
@@ -325,7 +326,6 @@ pub fn create_function_debug_context<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
325326 let function_type_metadata = unsafe {
326327 let fn_signature = get_function_signature ( cx,
327328 fn_ast_id,
328- & * fn_decl,
329329 param_substs,
330330 span) ;
331331 llvm:: LLVMDIBuilderCreateSubroutineType ( DIB ( cx) , file_metadata, fn_signature)
@@ -402,35 +402,49 @@ pub fn create_function_debug_context<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
402402
403403 fn get_function_signature < ' a , ' tcx > ( cx : & CrateContext < ' a , ' tcx > ,
404404 fn_ast_id : ast:: NodeId ,
405- fn_decl : & ast:: FnDecl ,
406405 param_substs : & Substs < ' tcx > ,
407406 error_reporting_span : Span ) -> DIArray {
408407 if cx. sess ( ) . opts . debuginfo == LimitedDebugInfo {
409408 return create_DIArray ( DIB ( cx) , & [ ] ) ;
410409 }
411410
412- let mut signature = Vec :: with_capacity ( fn_decl. inputs . len ( ) + 1 ) ;
413-
414411 // Return type -- llvm::DIBuilder wants this at index 0
415412 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 )
422441 } else {
423- signature . push ( type_metadata ( cx , return_type , codemap :: DUMMY_SP ) ) ;
424- }
442+ sig . inputs
443+ } ;
425444
426445 // 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 ) ) ;
434448 }
435449
436450 return create_DIArray ( DIB ( cx) , & signature[ ..] ) ;
0 commit comments