@@ -137,6 +137,13 @@ fn fcx_has_nonzero_span(fcx: &FunctionContext) -> bool {
137
137
}
138
138
}
139
139
140
+ fn span_is_empty ( opt_span : & Option < span > ) -> bool {
141
+ match * opt_span {
142
+ None => true ,
143
+ Some ( span) => * span. lo == 0 && * span. hi == 0
144
+ }
145
+ }
146
+
140
147
struct StatRecorder < ' self > {
141
148
ccx : @mut CrateContext ,
142
149
name : & ' self str ,
@@ -1624,6 +1631,13 @@ pub fn new_fn_ctxt_w_id(ccx: @mut CrateContext,
1624
1631
}
1625
1632
} ;
1626
1633
let uses_outptr = type_of:: return_uses_outptr ( ccx. tcx , substd_output_type) ;
1634
+
1635
+ let debug_context = if id != -1 && ccx. sess . opts . debuginfo && !span_is_empty ( & sp) {
1636
+ Some ( debuginfo:: create_function_debug_context ( ccx, id, param_substs, llfndecl) )
1637
+ } else {
1638
+ None
1639
+ } ;
1640
+
1627
1641
let fcx = @mut FunctionContext {
1628
1642
llfn : llfndecl,
1629
1643
llenv : unsafe {
@@ -1644,7 +1658,7 @@ pub fn new_fn_ctxt_w_id(ccx: @mut CrateContext,
1644
1658
span : sp,
1645
1659
path : path,
1646
1660
ccx : ccx,
1647
- debug_context : None ,
1661
+ debug_context : debug_context ,
1648
1662
} ;
1649
1663
fcx. llenv = unsafe {
1650
1664
llvm:: LLVMGetParam ( llfndecl, fcx. env_arg_pos ( ) as c_uint )
@@ -1877,6 +1891,7 @@ pub fn trans_closure(ccx: @mut CrateContext,
1877
1891
param_substs,
1878
1892
body. info ( ) ,
1879
1893
Some ( body. span ) ) ;
1894
+
1880
1895
let raw_llargs = create_llargs_for_fn_args ( fcx, self_arg, decl. inputs ) ;
1881
1896
1882
1897
// Set the fixed stack segment flag if necessary.
@@ -1885,10 +1900,6 @@ pub fn trans_closure(ccx: @mut CrateContext,
1885
1900
set_fixed_stack_segment ( fcx. llfn ) ;
1886
1901
}
1887
1902
1888
- if ccx. sess . opts . debuginfo && fcx_has_nonzero_span ( fcx) {
1889
- debuginfo:: create_function_metadata ( fcx) ;
1890
- }
1891
-
1892
1903
// Create the first basic block in the function and keep a handle on it to
1893
1904
// pass to finish_fn later.
1894
1905
let bcx_top = fcx. entry_bcx . unwrap ( ) ;
@@ -1900,6 +1911,11 @@ pub fn trans_closure(ccx: @mut CrateContext,
1900
1911
1901
1912
maybe_load_env ( fcx) ;
1902
1913
1914
+ // Up until here, IR instructions for this function have explicitly not been annotated with
1915
+ // source code location, so we don't step into call setup code. From here on, source location
1916
+ // emitting should be enabled.
1917
+ debuginfo:: start_emitting_source_locations ( fcx) ;
1918
+
1903
1919
// This call to trans_block is the place where we bridge between
1904
1920
// translation calls that don't have a return value (trans_crate,
1905
1921
// trans_mod, trans_item, et cetera) and those that do
0 commit comments