@@ -87,10 +87,6 @@ bool llvm::applyDebugifyMetadata(
87
87
return false ;
88
88
}
89
89
90
- bool NewDebugMode = M.IsNewDbgInfoFormat ;
91
- if (NewDebugMode)
92
- M.convertFromNewDbgValues ();
93
-
94
90
DIBuilder DIB (M);
95
91
LLVMContext &Ctx = M.getContext ();
96
92
auto *Int32Ty = Type::getInt32Ty (Ctx);
@@ -214,9 +210,6 @@ bool llvm::applyDebugifyMetadata(
214
210
if (!M.getModuleFlag (DIVersionKey))
215
211
M.addModuleFlag (Module::Warning, DIVersionKey, DEBUG_METADATA_VERSION);
216
212
217
- if (NewDebugMode)
218
- M.convertToNewDbgValues ();
219
-
220
213
return true ;
221
214
}
222
215
@@ -311,10 +304,6 @@ bool llvm::collectDebugInfoMetadata(Module &M,
311
304
return false ;
312
305
}
313
306
314
- bool NewDebugMode = M.IsNewDbgInfoFormat ;
315
- if (NewDebugMode)
316
- M.convertFromNewDbgValues ();
317
-
318
307
uint64_t FunctionsCnt = DebugInfoBeforePass.DIFunctions .size ();
319
308
// Visit each instruction.
320
309
for (Function &F : Functions) {
@@ -349,20 +338,23 @@ bool llvm::collectDebugInfoMetadata(Module &M,
349
338
350
339
// Cllect dbg.values and dbg.declare.
351
340
if (DebugifyLevel > Level::Locations) {
352
- if ( auto *DVI = dyn_cast<DbgVariableIntrinsic>(&I) ) {
341
+ auto HandleDbgVariable = [&]( auto *DbgVar ) {
353
342
if (!SP)
354
- continue ;
343
+ return ;
355
344
// Skip inlined variables.
356
- if (I. getDebugLoc ().getInlinedAt ())
357
- continue ;
345
+ if (DbgVar-> getDebugLoc ().getInlinedAt ())
346
+ return ;
358
347
// Skip undef values.
359
- if (DVI ->isKillLocation ())
360
- continue ;
348
+ if (DbgVar ->isKillLocation ())
349
+ return ;
361
350
362
- auto *Var = DVI ->getVariable ();
351
+ auto *Var = DbgVar ->getVariable ();
363
352
DebugInfoBeforePass.DIVariables [Var]++;
364
- continue ;
365
- }
353
+ };
354
+ for (DbgVariableRecord &DVR : filterDbgVars (I.getDbgRecordRange ()))
355
+ HandleDbgVariable (&DVR);
356
+ if (auto *DVI = dyn_cast<DbgVariableIntrinsic>(&I))
357
+ HandleDbgVariable (DVI);
366
358
}
367
359
368
360
// Skip debug instructions other than dbg.value and dbg.declare.
@@ -379,9 +371,6 @@ bool llvm::collectDebugInfoMetadata(Module &M,
379
371
}
380
372
}
381
373
382
- if (NewDebugMode)
383
- M.convertToNewDbgValues ();
384
-
385
374
return true ;
386
375
}
387
376
@@ -561,10 +550,6 @@ bool llvm::checkDebugInfoMetadata(Module &M,
561
550
return false ;
562
551
}
563
552
564
- bool NewDebugMode = M.IsNewDbgInfoFormat ;
565
- if (NewDebugMode)
566
- M.convertFromNewDbgValues ();
567
-
568
553
// Map the debug info holding DIs after a pass.
569
554
DebugInfoPerPass DebugInfoAfterPass;
570
555
@@ -599,20 +584,23 @@ bool llvm::checkDebugInfoMetadata(Module &M,
599
584
600
585
// Collect dbg.values and dbg.declares.
601
586
if (DebugifyLevel > Level::Locations) {
602
- if ( auto *DVI = dyn_cast<DbgVariableIntrinsic>(&I) ) {
587
+ auto HandleDbgVariable = [&]( auto *DbgVar ) {
603
588
if (!SP)
604
- continue ;
589
+ return ;
605
590
// Skip inlined variables.
606
- if (I. getDebugLoc ().getInlinedAt ())
607
- continue ;
591
+ if (DbgVar-> getDebugLoc ().getInlinedAt ())
592
+ return ;
608
593
// Skip undef values.
609
- if (DVI ->isKillLocation ())
610
- continue ;
594
+ if (DbgVar ->isKillLocation ())
595
+ return ;
611
596
612
- auto *Var = DVI ->getVariable ();
597
+ auto *Var = DbgVar ->getVariable ();
613
598
DebugInfoAfterPass.DIVariables [Var]++;
614
- continue ;
615
- }
599
+ };
600
+ for (DbgVariableRecord &DVR : filterDbgVars (I.getDbgRecordRange ()))
601
+ HandleDbgVariable (&DVR);
602
+ if (auto *DVI = dyn_cast<DbgVariableIntrinsic>(&I))
603
+ HandleDbgVariable (DVI);
616
604
}
617
605
618
606
// Skip debug instructions other than dbg.value and dbg.declare.
@@ -675,16 +663,14 @@ bool llvm::checkDebugInfoMetadata(Module &M,
675
663
// the debugging information from the previous pass.
676
664
DebugInfoBeforePass = DebugInfoAfterPass;
677
665
678
- if (NewDebugMode)
679
- M.convertToNewDbgValues ();
680
-
681
666
LLVM_DEBUG (dbgs () << " \n\n " );
682
667
return Result;
683
668
}
684
669
685
670
namespace {
686
- // / Return true if a mis-sized diagnostic is issued for \p DVI.
687
- bool diagnoseMisSizedDbgValue (Module &M, DbgValueInst *DVI) {
671
+ // / Return true if a mis-sized diagnostic is issued for \p DbgVal.
672
+ template <typename DbgValTy>
673
+ bool diagnoseMisSizedDbgValue (Module &M, DbgValTy *DbgVal) {
688
674
// The size of a dbg.value's value operand should match the size of the
689
675
// variable it corresponds to.
690
676
//
@@ -693,22 +679,22 @@ bool diagnoseMisSizedDbgValue(Module &M, DbgValueInst *DVI) {
693
679
694
680
// For now, don't try to interpret anything more complicated than an empty
695
681
// DIExpression. Eventually we should try to handle OP_deref and fragments.
696
- if (DVI ->getExpression ()->getNumElements ())
682
+ if (DbgVal ->getExpression ()->getNumElements ())
697
683
return false ;
698
684
699
- Value *V = DVI ->getVariableLocationOp (0 );
685
+ Value *V = DbgVal ->getVariableLocationOp (0 );
700
686
if (!V)
701
687
return false ;
702
688
703
689
Type *Ty = V->getType ();
704
690
uint64_t ValueOperandSize = getAllocSizeInBits (M, Ty);
705
- std::optional<uint64_t > DbgVarSize = DVI ->getFragmentSizeInBits ();
691
+ std::optional<uint64_t > DbgVarSize = DbgVal ->getFragmentSizeInBits ();
706
692
if (!ValueOperandSize || !DbgVarSize)
707
693
return false ;
708
694
709
695
bool HasBadSize = false ;
710
696
if (Ty->isIntegerTy ()) {
711
- auto Signedness = DVI ->getVariable ()->getSignedness ();
697
+ auto Signedness = DbgVal ->getVariable ()->getSignedness ();
712
698
if (Signedness && *Signedness == DIBasicType::Signedness::Signed)
713
699
HasBadSize = ValueOperandSize < *DbgVarSize;
714
700
} else {
@@ -718,7 +704,7 @@ bool diagnoseMisSizedDbgValue(Module &M, DbgValueInst *DVI) {
718
704
if (HasBadSize) {
719
705
dbg () << " ERROR: dbg.value operand has size " << ValueOperandSize
720
706
<< " , but its variable has size " << *DbgVarSize << " : " ;
721
- DVI ->print (dbg ());
707
+ DbgVal ->print (dbg ());
722
708
dbg () << " \n " ;
723
709
}
724
710
return HasBadSize;
@@ -735,10 +721,6 @@ bool checkDebugifyMetadata(Module &M,
735
721
return false ;
736
722
}
737
723
738
- bool NewDebugMode = M.IsNewDbgInfoFormat ;
739
- if (NewDebugMode)
740
- M.convertFromNewDbgValues ();
741
-
742
724
auto getDebugifyOperand = [&](unsigned Idx) -> unsigned {
743
725
return mdconst::extract<ConstantInt>(NMD->getOperand (Idx)->getOperand (0 ))
744
726
->getZExtValue ();
@@ -780,18 +762,23 @@ bool checkDebugifyMetadata(Module &M,
780
762
}
781
763
782
764
// Find missing variables and mis-sized debug values.
783
- for (Instruction &I : instructions (F)) {
784
- auto *DVI = dyn_cast<DbgValueInst>(&I);
785
- if (!DVI)
786
- continue ;
787
-
765
+ auto CheckForMisSized = [&](auto *DbgVal) {
788
766
unsigned Var = ~0U ;
789
- (void )to_integer (DVI ->getVariable ()->getName (), Var, 10 );
767
+ (void )to_integer (DbgVal ->getVariable ()->getName (), Var, 10 );
790
768
assert (Var <= OriginalNumVars && " Unexpected name for DILocalVariable" );
791
- bool HasBadSize = diagnoseMisSizedDbgValue (M, DVI );
769
+ bool HasBadSize = diagnoseMisSizedDbgValue (M, DbgVal );
792
770
if (!HasBadSize)
793
771
MissingVars.reset (Var - 1 );
794
772
HasErrors |= HasBadSize;
773
+ };
774
+ for (Instruction &I : instructions (F)) {
775
+ for (DbgVariableRecord &DVR : filterDbgVars (I.getDbgRecordRange ()))
776
+ if (DVR.isDbgValue () || DVR.isDbgAssign ())
777
+ CheckForMisSized (&DVR);
778
+ auto *DVI = dyn_cast<DbgValueInst>(&I);
779
+ if (!DVI)
780
+ continue ;
781
+ CheckForMisSized (DVI);
795
782
}
796
783
}
797
784
@@ -820,9 +807,6 @@ bool checkDebugifyMetadata(Module &M,
820
807
if (Strip)
821
808
Ret = stripDebugifyMetadata (M);
822
809
823
- if (NewDebugMode)
824
- M.convertToNewDbgValues ();
825
-
826
810
return Ret;
827
811
}
828
812
@@ -1052,10 +1036,6 @@ FunctionPass *createCheckDebugifyFunctionPass(
1052
1036
1053
1037
PreservedAnalyses NewPMCheckDebugifyPass::run (Module &M,
1054
1038
ModuleAnalysisManager &) {
1055
- bool NewDebugMode = M.IsNewDbgInfoFormat ;
1056
- if (NewDebugMode)
1057
- M.convertFromNewDbgValues ();
1058
-
1059
1039
if (Mode == DebugifyMode::SyntheticDebugInfo)
1060
1040
checkDebugifyMetadata (M, M.functions (), NameOfWrappedPass,
1061
1041
" CheckModuleDebugify" , Strip, StatsMap);
@@ -1065,9 +1045,6 @@ PreservedAnalyses NewPMCheckDebugifyPass::run(Module &M,
1065
1045
" CheckModuleDebugify (original debuginfo)" , NameOfWrappedPass,
1066
1046
OrigDIVerifyBugsReportFilePath);
1067
1047
1068
- if (NewDebugMode)
1069
- M.convertToNewDbgValues ();
1070
-
1071
1048
return PreservedAnalyses::all ();
1072
1049
}
1073
1050
0 commit comments