@@ -545,6 +545,7 @@ class Verifier : public InstVisitor<Verifier>, VerifierSupport {
545
545
void visit (DPValue &DPV);
546
546
// InstVisitor overrides...
547
547
using InstVisitor<Verifier>::visit;
548
+ void visitDbgRecords (Instruction &I);
548
549
void visit (Instruction &I);
549
550
550
551
void visitTruncInst (TruncInst &I);
@@ -670,9 +671,19 @@ class Verifier : public InstVisitor<Verifier>, VerifierSupport {
670
671
} \
671
672
} while (false )
672
673
673
- void Verifier::visit (Instruction &I) {
674
- for (auto &DPV : I.getDbgValueRange ())
674
+ void Verifier::visitDbgRecords (Instruction &I) {
675
+ if (!I.DbgMarker )
676
+ return ;
677
+ CheckDI (I.DbgMarker ->MarkedInstr == &I, " Instruction has invalid DbgMarker" , &I);
678
+ CheckDI (!isa<PHINode>(&I) || !I.hasDbgValues (), " PHI Node must not have any attached DbgRecords" , &I);
679
+ for (auto &DPV : I.getDbgValueRange ()) {
680
+ CheckDI (DPV.getMarker () == I.DbgMarker , " DbgRecord had invalid DbgMarker" , &I, &DPV);
675
681
visit (DPV);
682
+ }
683
+ }
684
+
685
+ void Verifier::visit (Instruction &I) {
686
+ visitDbgRecords (I);
676
687
for (unsigned i = 0 , e = I.getNumOperands (); i != e; ++i)
677
688
Check (I.getOperand (i) != nullptr , " Operand is null" , &I);
678
689
InstVisitor<Verifier>::visit (I);
@@ -3000,6 +3011,7 @@ void Verifier::visitBasicBlock(BasicBlock &BB) {
3000
3011
3001
3012
// Confirm that no issues arise from the debug program.
3002
3013
if (BB.IsNewDbgInfoFormat ) {
3014
+ CheckDI (!BB.getTrailingDPValues (), " Basic Block has trailing DbgRecords!" , &BB);
3003
3015
// Configure the validate function to not fire assertions, instead print
3004
3016
// errors and return true if there's a problem.
3005
3017
bool RetVal = BB.validateDbgValues (false , true , OS);
@@ -6176,33 +6188,24 @@ void Verifier::visit(DPValue &DPV) {
6176
6188
DPV.getType () == DPValue::LocationType::Declare ||
6177
6189
DPV.getType () == DPValue::LocationType::Assign,
6178
6190
" invalid #dbg record type" , &DPV, DPV.getType ());
6179
- StringRef Kind;
6180
- switch (DPV.getType ()) {
6181
- case DPValue::LocationType::Value:
6182
- Kind = " value" ;
6183
- break ;
6184
- case DPValue::LocationType::Declare:
6185
- Kind = " declare" ;
6186
- break ;
6187
- case DPValue::LocationType::Assign:
6188
- Kind = " assign" ;
6189
- break ;
6190
- default :
6191
- llvm_unreachable (" Tried to print a DPValue with an invalid LocationType!" );
6192
- };
6191
+ // The location for a DPValue must be either a ValueAsMetadata, DIArgList, or
6192
+ // an empty MDNode (which is a legacy representation for an "undef" location).
6193
6193
auto *MD = DPV.getRawLocation ();
6194
6194
CheckDI (isa<ValueAsMetadata>(MD) || isa<DIArgList>(MD) ||
6195
6195
(isa<MDNode>(MD) && !cast<MDNode>(MD)->getNumOperands ()),
6196
- " invalid #dbg_ " + Kind + " address/value" , &DPV, MD);
6196
+ " invalid #dbg record address/value" , &DPV, MD);
6197
6197
CheckDI (isa<DILocalVariable>(DPV.getRawVariable ()),
6198
- " invalid #dbg_ " + Kind + " variable" , &DPV, DPV.getRawVariable ());
6199
- CheckDI (DPV.getExpression (), " missing #dbg_ " + Kind + " expression" , &DPV,
6198
+ " invalid #dbg record variable" , &DPV, DPV.getRawVariable ());
6199
+ CheckDI (DPV.getExpression (), " missing #dbg record expression" , &DPV,
6200
6200
DPV.getExpression ());
6201
6201
6202
6202
if (DPV.isDbgAssign ()) {
6203
6203
CheckDI (isa<DIAssignID>(DPV.getRawAssignID ()),
6204
6204
" invalid #dbg_assign DIAssignID" , &DPV, DPV.getRawAssignID ());
6205
6205
const auto *RawAddr = DPV.getRawAddress ();
6206
+ // Similarly to the location above, the address for an assign DPValue must
6207
+ // be a ValueAsMetadata or an empty MDNode, which represents an undef
6208
+ // address.
6206
6209
CheckDI (
6207
6210
isa<ValueAsMetadata>(RawAddr) ||
6208
6211
(isa<MDNode>(RawAddr) && !cast<MDNode>(RawAddr)->getNumOperands ()),
@@ -6217,7 +6220,7 @@ void Verifier::visit(DPValue &DPV) {
6217
6220
}
6218
6221
6219
6222
if (MDNode *N = DPV.getDebugLoc ().getAsMDNode ()) {
6220
- CheckDI (isa<DILocation>(N), " invalid #dbg_ " + Kind + " location" , &DPV, N);
6223
+ CheckDI (isa<DILocation>(N), " invalid #dbg record location" , &DPV, N);
6221
6224
visitDILocation (*cast<DILocation>(N));
6222
6225
}
6223
6226
@@ -6227,16 +6230,15 @@ void Verifier::visit(DPValue &DPV) {
6227
6230
// The scopes for variables and !dbg attachments must agree.
6228
6231
DILocalVariable *Var = DPV.getVariable ();
6229
6232
DILocation *Loc = DPV.getDebugLoc ();
6230
- CheckDI (Loc, " missing #dbg_ " + Kind + " DILocation" , &DPV, BB, F);
6233
+ CheckDI (Loc, " missing #dbg record DILocation" , &DPV, BB, F);
6231
6234
6232
6235
DISubprogram *VarSP = getSubprogram (Var->getRawScope ());
6233
6236
DISubprogram *LocSP = getSubprogram (Loc->getRawScope ());
6234
6237
if (!VarSP || !LocSP)
6235
6238
return ; // Broken scope chains are checked elsewhere.
6236
6239
6237
6240
CheckDI (VarSP == LocSP,
6238
- " mismatched subprogram between #dbg_" + Kind +
6239
- " variable and DILocation" ,
6241
+ " mismatched subprogram between #dbg record variable and DILocation" ,
6240
6242
&DPV, BB, F, Var, Var->getScope ()->getSubprogram (), Loc,
6241
6243
Loc->getScope ()->getSubprogram ());
6242
6244
0 commit comments