11use std:: collections:: hash_map:: Entry ;
2+ use std:: marker:: PhantomData ;
23use std:: ops:: Range ;
34
45use rustc_data_structures:: fx:: FxHashMap ;
@@ -14,7 +15,7 @@ use rustc_target::abi::{Abi, FieldIdx, FieldsShape, Size, VariantIdx};
1415
1516use super :: operand:: { OperandRef , OperandValue } ;
1617use super :: place:: { PlaceRef , PlaceValue } ;
17- use super :: { FunctionCx , LocalRef } ;
18+ use super :: { FunctionCx , LocalRef , PerLocalVarDebugInfoIndexVec } ;
1819use crate :: traits:: * ;
1920
2021pub struct FunctionDebugContext < ' tcx , S , L > {
@@ -48,6 +49,17 @@ pub struct PerLocalVarDebugInfo<'tcx, D> {
4849 pub projection : & ' tcx ty:: List < mir:: PlaceElem < ' tcx > > ,
4950}
5051
52+ /// Information needed to emit a constant.
53+ pub struct ConstDebugInfo < ' a , ' tcx , Bx : BuilderMethods < ' a , ' tcx > > {
54+ pub name : String ,
55+ pub source_info : mir:: SourceInfo ,
56+ pub operand : OperandRef < ' tcx , Bx :: Value > ,
57+ pub dbg_var : Bx :: DIVariable ,
58+ pub dbg_loc : Bx :: DILocation ,
59+ pub fragment : Option < Range < Size > > ,
60+ pub _phantom : PhantomData < & ' a ( ) > ,
61+ }
62+
5163#[ derive( Clone , Copy , Debug ) ]
5264pub struct DebugScope < S , L > {
5365 pub dbg_scope : S ,
@@ -427,19 +439,36 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
427439 }
428440 }
429441
430- pub ( crate ) fn debug_introduce_locals ( & self , bx : & mut Bx ) {
442+ pub ( crate ) fn debug_introduce_locals (
443+ & self ,
444+ bx : & mut Bx ,
445+ consts : Vec < ConstDebugInfo < ' a , ' tcx , Bx > > ,
446+ ) {
431447 if bx. sess ( ) . opts . debuginfo == DebugInfo :: Full || !bx. sess ( ) . fewer_names ( ) {
432448 for local in self . locals . indices ( ) {
433449 self . debug_introduce_local ( bx, local) ;
434450 }
451+
452+ for ConstDebugInfo { name, source_info, operand, dbg_var, dbg_loc, fragment, .. } in
453+ consts. into_iter ( )
454+ {
455+ self . set_debug_loc ( bx, source_info) ;
456+ let base = FunctionCx :: spill_operand_to_stack ( operand, Some ( name) , bx) ;
457+ bx. clear_dbg_loc ( ) ;
458+
459+ bx. dbg_var_addr ( dbg_var, dbg_loc, base. val . llval , Size :: ZERO , & [ ] , fragment) ;
460+ }
435461 }
436462 }
437463
438464 /// Partition all `VarDebugInfo` in `self.mir`, by their base `Local`.
439465 pub ( crate ) fn compute_per_local_var_debug_info (
440466 & self ,
441467 bx : & mut Bx ,
442- ) -> Option < IndexVec < mir:: Local , Vec < PerLocalVarDebugInfo < ' tcx , Bx :: DIVariable > > > > {
468+ ) -> Option < (
469+ PerLocalVarDebugInfoIndexVec < ' tcx , Bx :: DIVariable > ,
470+ Vec < ConstDebugInfo < ' a , ' tcx , Bx > > ,
471+ ) > {
443472 let full_debug_info = self . cx . sess ( ) . opts . debuginfo == DebugInfo :: Full ;
444473
445474 let target_is_msvc = self . cx . sess ( ) . target . is_like_msvc ;
@@ -449,6 +478,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
449478 }
450479
451480 let mut per_local = IndexVec :: from_elem ( vec ! [ ] , & self . mir . local_decls ) ;
481+ let mut constants = vec ! [ ] ;
452482 let mut params_seen: FxHashMap < _ , Bx :: DIVariable > = Default :: default ( ) ;
453483 for var in & self . mir . var_debug_info {
454484 let dbg_scope_and_span = if full_debug_info {
@@ -545,23 +575,19 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
545575 let Some ( dbg_loc) = self . dbg_loc ( var. source_info ) else { continue } ;
546576
547577 let operand = self . eval_mir_constant_to_operand ( bx, & c) ;
548- self . set_debug_loc ( bx, var. source_info ) ;
549- let base =
550- Self :: spill_operand_to_stack ( operand, Some ( var. name . to_string ( ) ) , bx) ;
551- bx. clear_dbg_loc ( ) ;
552-
553- bx. dbg_var_addr (
578+ constants. push ( ConstDebugInfo {
579+ name : var. name . to_string ( ) ,
580+ source_info : var. source_info ,
581+ operand,
554582 dbg_var,
555583 dbg_loc,
556- base. val . llval ,
557- Size :: ZERO ,
558- & [ ] ,
559584 fragment,
560- ) ;
585+ _phantom : PhantomData ,
586+ } ) ;
561587 }
562588 }
563589 }
564590 }
565- Some ( per_local)
591+ Some ( ( per_local, constants ) )
566592 }
567593}
0 commit comments