1
1
use std:: collections:: hash_map:: Entry ;
2
+ use std:: marker:: PhantomData ;
2
3
use std:: ops:: Range ;
3
4
4
5
use rustc_data_structures:: fx:: FxHashMap ;
@@ -14,7 +15,7 @@ use rustc_target::abi::{Abi, FieldIdx, FieldsShape, Size, VariantIdx};
14
15
15
16
use super :: operand:: { OperandRef , OperandValue } ;
16
17
use super :: place:: { PlaceRef , PlaceValue } ;
17
- use super :: { FunctionCx , LocalRef } ;
18
+ use super :: { FunctionCx , LocalRef , PerLocalVarDebugInfoIndexVec } ;
18
19
use crate :: traits:: * ;
19
20
20
21
pub struct FunctionDebugContext < ' tcx , S , L > {
@@ -48,6 +49,17 @@ pub struct PerLocalVarDebugInfo<'tcx, D> {
48
49
pub projection : & ' tcx ty:: List < mir:: PlaceElem < ' tcx > > ,
49
50
}
50
51
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
+
51
63
#[ derive( Clone , Copy , Debug ) ]
52
64
pub struct DebugScope < S , L > {
53
65
pub dbg_scope : S ,
@@ -427,19 +439,36 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
427
439
}
428
440
}
429
441
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
+ ) {
431
447
if bx. sess ( ) . opts . debuginfo == DebugInfo :: Full || !bx. sess ( ) . fewer_names ( ) {
432
448
for local in self . locals . indices ( ) {
433
449
self . debug_introduce_local ( bx, local) ;
434
450
}
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
+ }
435
461
}
436
462
}
437
463
438
464
/// Partition all `VarDebugInfo` in `self.mir`, by their base `Local`.
439
465
pub ( crate ) fn compute_per_local_var_debug_info (
440
466
& self ,
441
467
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
+ ) > {
443
472
let full_debug_info = self . cx . sess ( ) . opts . debuginfo == DebugInfo :: Full ;
444
473
445
474
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> {
449
478
}
450
479
451
480
let mut per_local = IndexVec :: from_elem ( vec ! [ ] , & self . mir . local_decls ) ;
481
+ let mut constants = vec ! [ ] ;
452
482
let mut params_seen: FxHashMap < _ , Bx :: DIVariable > = Default :: default ( ) ;
453
483
for var in & self . mir . var_debug_info {
454
484
let dbg_scope_and_span = if full_debug_info {
@@ -545,23 +575,19 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
545
575
let Some ( dbg_loc) = self . dbg_loc ( var. source_info ) else { continue } ;
546
576
547
577
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,
554
582
dbg_var,
555
583
dbg_loc,
556
- base. val . llval ,
557
- Size :: ZERO ,
558
- & [ ] ,
559
584
fragment,
560
- ) ;
585
+ _phantom : PhantomData ,
586
+ } ) ;
561
587
}
562
588
}
563
589
}
564
590
}
565
- Some ( per_local)
591
+ Some ( ( per_local, constants ) )
566
592
}
567
593
}
0 commit comments