@@ -173,11 +173,36 @@ struct VerifierSupport {
173
173
}
174
174
}
175
175
176
+ void Write (const DbgRecord *DR) {
177
+ if (DR)
178
+ DR->print (*OS, MST, false );
179
+ }
180
+
176
181
void Write (const DPValue *V) {
177
182
if (V)
178
183
V->print (*OS, MST, false );
179
184
}
180
185
186
+ void Write (DPValue::LocationType Type) {
187
+ switch (Type) {
188
+ case DPValue::LocationType::Value:
189
+ *OS << " value" ;
190
+ break ;
191
+ case DPValue::LocationType::Declare:
192
+ *OS << " declare" ;
193
+ break ;
194
+ case DPValue::LocationType::Assign:
195
+ *OS << " assign" ;
196
+ break ;
197
+ case DPValue::LocationType::End:
198
+ *OS << " end" ;
199
+ break ;
200
+ case DPValue::LocationType::Any:
201
+ *OS << " any" ;
202
+ break ;
203
+ };
204
+ }
205
+
181
206
void Write (const Metadata *MD) {
182
207
if (!MD)
183
208
return ;
@@ -522,8 +547,10 @@ class Verifier : public InstVisitor<Verifier>, VerifierSupport {
522
547
523
548
void visitTemplateParams (const MDNode &N, const Metadata &RawParams);
524
549
550
+ void visit (DPValue &DPV);
525
551
// InstVisitor overrides...
526
552
using InstVisitor<Verifier>::visit;
553
+ void visitDbgRecords (Instruction &I);
527
554
void visit (Instruction &I);
528
555
529
556
void visitTruncInst (TruncInst &I);
@@ -649,7 +676,22 @@ class Verifier : public InstVisitor<Verifier>, VerifierSupport {
649
676
} \
650
677
} while (false )
651
678
679
+ void Verifier::visitDbgRecords (Instruction &I) {
680
+ if (!I.DbgMarker )
681
+ return ;
682
+ CheckDI (I.DbgMarker ->MarkedInstr == &I, " Instruction has invalid DbgMarker" ,
683
+ &I);
684
+ CheckDI (!isa<PHINode>(&I) || !I.hasDbgValues (),
685
+ " PHI Node must not have any attached DbgRecords" , &I);
686
+ for (DPValue &DPV : DPValue::filter (I.getDbgValueRange ())) {
687
+ CheckDI (DPV.getMarker () == I.DbgMarker , " DbgRecord had invalid DbgMarker" ,
688
+ &I, &DPV);
689
+ visit (DPV);
690
+ }
691
+ }
692
+
652
693
void Verifier::visit (Instruction &I) {
694
+ visitDbgRecords (I);
653
695
for (unsigned i = 0 , e = I.getNumOperands (); i != e; ++i)
654
696
Check (I.getOperand (i) != nullptr , " Operand is null" , &I);
655
697
InstVisitor<Verifier>::visit (I);
@@ -2976,12 +3018,9 @@ void Verifier::visitBasicBlock(BasicBlock &BB) {
2976
3018
}
2977
3019
2978
3020
// Confirm that no issues arise from the debug program.
2979
- if (BB.IsNewDbgInfoFormat ) {
2980
- // Configure the validate function to not fire assertions, instead print
2981
- // errors and return true if there's a problem.
2982
- bool RetVal = BB.validateDbgValues (false , true , OS);
2983
- Check (!RetVal, " Invalid configuration of new-debug-info data found" );
2984
- }
3021
+ if (BB.IsNewDbgInfoFormat )
3022
+ CheckDI (!BB.getTrailingDPValues (), " Basic Block has trailing DbgRecords!" ,
3023
+ &BB);
2985
3024
}
2986
3025
2987
3026
void Verifier::visitTerminator (Instruction &I) {
@@ -6148,6 +6187,70 @@ static DISubprogram *getSubprogram(Metadata *LocalScope) {
6148
6187
return nullptr ;
6149
6188
}
6150
6189
6190
+ void Verifier::visit (DPValue &DPV) {
6191
+ CheckDI (DPV.getType () == DPValue::LocationType::Value ||
6192
+ DPV.getType () == DPValue::LocationType::Declare ||
6193
+ DPV.getType () == DPValue::LocationType::Assign,
6194
+ " invalid #dbg record type" , &DPV, DPV.getType ());
6195
+ // The location for a DPValue must be either a ValueAsMetadata, DIArgList, or
6196
+ // an empty MDNode (which is a legacy representation for an "undef" location).
6197
+ auto *MD = DPV.getRawLocation ();
6198
+ CheckDI (isa<ValueAsMetadata>(MD) || isa<DIArgList>(MD) ||
6199
+ (isa<MDNode>(MD) && !cast<MDNode>(MD)->getNumOperands ()),
6200
+ " invalid #dbg record address/value" , &DPV, MD);
6201
+ CheckDI (isa<DILocalVariable>(DPV.getRawVariable ()),
6202
+ " invalid #dbg record variable" , &DPV, DPV.getRawVariable ());
6203
+ CheckDI (DPV.getExpression (), " missing #dbg record expression" , &DPV,
6204
+ DPV.getExpression ());
6205
+
6206
+ if (DPV.isDbgAssign ()) {
6207
+ CheckDI (isa<DIAssignID>(DPV.getRawAssignID ()),
6208
+ " invalid #dbg_assign DIAssignID" , &DPV, DPV.getRawAssignID ());
6209
+ const auto *RawAddr = DPV.getRawAddress ();
6210
+ // Similarly to the location above, the address for an assign DPValue must
6211
+ // be a ValueAsMetadata or an empty MDNode, which represents an undef
6212
+ // address.
6213
+ CheckDI (
6214
+ isa<ValueAsMetadata>(RawAddr) ||
6215
+ (isa<MDNode>(RawAddr) && !cast<MDNode>(RawAddr)->getNumOperands ()),
6216
+ " invalid #dbg_assign address" , &DPV, DPV.getRawAddress ());
6217
+ CheckDI (DPV.getAddressExpression (),
6218
+ " missing #dbg_assign address expression" , &DPV,
6219
+ DPV.getAddressExpression ());
6220
+ // All of the linked instructions should be in the same function as DPV.
6221
+ for (Instruction *I : at::getAssignmentInsts (&DPV))
6222
+ CheckDI (DPV.getFunction () == I->getFunction (),
6223
+ " inst not in same function as #dbg_assign" , I, &DPV);
6224
+ }
6225
+
6226
+ if (MDNode *N = DPV.getDebugLoc ().getAsMDNode ()) {
6227
+ CheckDI (isa<DILocation>(N), " invalid #dbg record location" , &DPV, N);
6228
+ visitDILocation (*cast<DILocation>(N));
6229
+ }
6230
+
6231
+ BasicBlock *BB = DPV.getParent ();
6232
+ Function *F = BB ? BB->getParent () : nullptr ;
6233
+
6234
+ // The scopes for variables and !dbg attachments must agree.
6235
+ DILocalVariable *Var = DPV.getVariable ();
6236
+ DILocation *Loc = DPV.getDebugLoc ();
6237
+ CheckDI (Loc, " missing #dbg record DILocation" , &DPV, BB, F);
6238
+
6239
+ DISubprogram *VarSP = getSubprogram (Var->getRawScope ());
6240
+ DISubprogram *LocSP = getSubprogram (Loc->getRawScope ());
6241
+ if (!VarSP || !LocSP)
6242
+ return ; // Broken scope chains are checked elsewhere.
6243
+
6244
+ CheckDI (VarSP == LocSP,
6245
+ " mismatched subprogram between #dbg record variable and DILocation" ,
6246
+ &DPV, BB, F, Var, Var->getScope ()->getSubprogram (), Loc,
6247
+ Loc->getScope ()->getSubprogram ());
6248
+
6249
+ // This check is redundant with one in visitLocalVariable().
6250
+ CheckDI (isType (Var->getRawType ()), " invalid type ref" , Var,
6251
+ Var->getRawType ());
6252
+ }
6253
+
6151
6254
void Verifier::visitVPIntrinsic (VPIntrinsic &VPI) {
6152
6255
if (auto *VPCast = dyn_cast<VPCastIntrinsic>(&VPI)) {
6153
6256
auto *RetTy = cast<VectorType>(VPCast->getType ());
0 commit comments