@@ -358,54 +358,56 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
358358 let vars = vars. iter ( ) . cloned ( ) . chain ( fallback_var) ;
359359
360360 for var in vars {
361- let Some ( dbg_var) = var. dbg_var else { continue } ;
362- let Some ( dbg_loc) = self . dbg_loc ( var. source_info ) else { continue } ;
363-
364- let DebugInfoOffset { direct_offset, indirect_offsets, result : _ } =
365- calculate_debuginfo_offset ( bx, local, & var, base. layout ) ;
366-
367- // When targeting MSVC, create extra allocas for arguments instead of pointing multiple
368- // dbg_var_addr() calls into the same alloca with offsets. MSVC uses CodeView records
369- // not DWARF and LLVM doesn't support translating the resulting
370- // [DW_OP_deref, DW_OP_plus_uconst, offset, DW_OP_deref] debug info to CodeView.
371- // Creating extra allocas on the stack makes the resulting debug info simple enough
372- // that LLVM can generate correct CodeView records and thus the values appear in the
373- // debugger. (#83709)
374- let should_create_individual_allocas = bx. cx ( ) . sess ( ) . target . is_like_msvc
375- && self . mir . local_kind ( local) == mir:: LocalKind :: Arg
376- // LLVM can handle simple things but anything more complex than just a direct
377- // offset or one indirect offset of 0 is too complex for it to generate CV records
378- // correctly.
379- && ( direct_offset != Size :: ZERO
380- || !matches ! ( & indirect_offsets[ ..] , [ Size :: ZERO ] | [ ] ) ) ;
381-
382- if should_create_individual_allocas {
383- let DebugInfoOffset { direct_offset : _, indirect_offsets : _, result : place } =
384- calculate_debuginfo_offset ( bx, local, & var, base) ;
385-
386- // Create a variable which will be a pointer to the actual value
387- let ptr_ty = bx
388- . tcx ( )
389- . mk_ptr ( ty:: TypeAndMut { mutbl : mir:: Mutability :: Mut , ty : place. layout . ty } ) ;
390- let ptr_layout = bx. layout_of ( ptr_ty) ;
391- let alloca = PlaceRef :: alloca ( bx, ptr_layout) ;
392- bx. set_var_name ( alloca. llval , & ( var. name . to_string ( ) + ".dbg.spill" ) ) ;
393-
394- // Write the pointer to the variable
395- bx. store ( place. llval , alloca. llval , alloca. align ) ;
396-
397- // Point the debug info to `*alloca` for the current variable
398- bx. dbg_var_addr ( dbg_var, dbg_loc, alloca. llval , Size :: ZERO , & [ Size :: ZERO ] , None ) ;
399- } else {
400- bx. dbg_var_addr (
401- dbg_var,
402- dbg_loc,
403- base. llval ,
404- direct_offset,
405- & indirect_offsets,
406- None ,
407- ) ;
408- }
361+ self . debug_introduce_local_as_var ( bx, local, base, var) ;
362+ }
363+ }
364+
365+ fn debug_introduce_local_as_var (
366+ & self ,
367+ bx : & mut Bx ,
368+ local : mir:: Local ,
369+ base : PlaceRef < ' tcx , Bx :: Value > ,
370+ var : PerLocalVarDebugInfo < ' tcx , Bx :: DIVariable > ,
371+ ) {
372+ let Some ( dbg_var) = var. dbg_var else { return } ;
373+ let Some ( dbg_loc) = self . dbg_loc ( var. source_info ) else { return } ;
374+
375+ let DebugInfoOffset { direct_offset, indirect_offsets, result : _ } =
376+ calculate_debuginfo_offset ( bx, local, & var, base. layout ) ;
377+
378+ // When targeting MSVC, create extra allocas for arguments instead of pointing multiple
379+ // dbg_var_addr() calls into the same alloca with offsets. MSVC uses CodeView records
380+ // not DWARF and LLVM doesn't support translating the resulting
381+ // [DW_OP_deref, DW_OP_plus_uconst, offset, DW_OP_deref] debug info to CodeView.
382+ // Creating extra allocas on the stack makes the resulting debug info simple enough
383+ // that LLVM can generate correct CodeView records and thus the values appear in the
384+ // debugger. (#83709)
385+ let should_create_individual_allocas = bx. cx ( ) . sess ( ) . target . is_like_msvc
386+ && self . mir . local_kind ( local) == mir:: LocalKind :: Arg
387+ // LLVM can handle simple things but anything more complex than just a direct
388+ // offset or one indirect offset of 0 is too complex for it to generate CV records
389+ // correctly.
390+ && ( direct_offset != Size :: ZERO || !matches ! ( & indirect_offsets[ ..] , [ Size :: ZERO ] | [ ] ) ) ;
391+
392+ if should_create_individual_allocas {
393+ let DebugInfoOffset { direct_offset : _, indirect_offsets : _, result : place } =
394+ calculate_debuginfo_offset ( bx, local, & var, base) ;
395+
396+ // Create a variable which will be a pointer to the actual value
397+ let ptr_ty = bx
398+ . tcx ( )
399+ . mk_ptr ( ty:: TypeAndMut { mutbl : mir:: Mutability :: Mut , ty : place. layout . ty } ) ;
400+ let ptr_layout = bx. layout_of ( ptr_ty) ;
401+ let alloca = PlaceRef :: alloca ( bx, ptr_layout) ;
402+ bx. set_var_name ( alloca. llval , & ( var. name . to_string ( ) + ".dbg.spill" ) ) ;
403+
404+ // Write the pointer to the variable
405+ bx. store ( place. llval , alloca. llval , alloca. align ) ;
406+
407+ // Point the debug info to `*alloca` for the current variable
408+ bx. dbg_var_addr ( dbg_var, dbg_loc, alloca. llval , Size :: ZERO , & [ Size :: ZERO ] , None ) ;
409+ } else {
410+ bx. dbg_var_addr ( dbg_var, dbg_loc, base. llval , direct_offset, & indirect_offsets, None ) ;
409411 }
410412 }
411413
0 commit comments