@@ -178,6 +178,26 @@ struct VerifierSupport {
178
178
V->print (*OS, MST, false );
179
179
}
180
180
181
+ void Write (DPValue::LocationType Type) {
182
+ switch (Type) {
183
+ case DPValue::LocationType::Value:
184
+ *OS << " value" ;
185
+ break ;
186
+ case DPValue::LocationType::Declare:
187
+ *OS << " declare" ;
188
+ break ;
189
+ case DPValue::LocationType::Assign:
190
+ *OS << " assign" ;
191
+ break ;
192
+ case DPValue::LocationType::End:
193
+ *OS << " end" ;
194
+ break ;
195
+ case DPValue::LocationType::Any:
196
+ *OS << " any" ;
197
+ break ;
198
+ };
199
+ }
200
+
181
201
void Write (const Metadata *MD) {
182
202
if (!MD)
183
203
return ;
@@ -522,6 +542,7 @@ class Verifier : public InstVisitor<Verifier>, VerifierSupport {
522
542
523
543
void visitTemplateParams (const MDNode &N, const Metadata &RawParams);
524
544
545
+ void visit (DPValue &DPV);
525
546
// InstVisitor overrides...
526
547
using InstVisitor<Verifier>::visit;
527
548
void visit (Instruction &I);
@@ -650,6 +671,8 @@ class Verifier : public InstVisitor<Verifier>, VerifierSupport {
650
671
} while (false )
651
672
652
673
void Verifier::visit (Instruction &I) {
674
+ for (auto &DPV : I.getDbgValueRange ())
675
+ visit (DPV);
653
676
for (unsigned i = 0 , e = I.getNumOperands (); i != e; ++i)
654
677
Check (I.getOperand (i) != nullptr , " Operand is null" , &I);
655
678
InstVisitor<Verifier>::visit (I);
@@ -6148,6 +6171,80 @@ static DISubprogram *getSubprogram(Metadata *LocalScope) {
6148
6171
return nullptr ;
6149
6172
}
6150
6173
6174
+ void Verifier::visit (DPValue &DPV) {
6175
+ CheckDI (DPV.getType () == DPValue::LocationType::Value ||
6176
+ DPV.getType () == DPValue::LocationType::Declare ||
6177
+ DPV.getType () == DPValue::LocationType::Assign,
6178
+ " 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
+ };
6193
+ auto *MD = DPV.getRawLocation ();
6194
+ CheckDI (isa<ValueAsMetadata>(MD) || isa<DIArgList>(MD) ||
6195
+ (isa<MDNode>(MD) && !cast<MDNode>(MD)->getNumOperands ()),
6196
+ " invalid #dbg_" + Kind + " address/value" , &DPV, MD);
6197
+ CheckDI (isa<DILocalVariable>(DPV.getRawVariable ()),
6198
+ " invalid #dbg_" + Kind + " variable" , &DPV, DPV.getRawVariable ());
6199
+ CheckDI (DPV.getExpression (), " missing #dbg_" + Kind + " expression" , &DPV,
6200
+ DPV.getExpression ());
6201
+
6202
+ if (DPV.isDbgAssign ()) {
6203
+ CheckDI (isa<DIAssignID>(DPV.getRawAssignID ()),
6204
+ " invalid #dbg_assign DIAssignID" , &DPV, DPV.getRawAssignID ());
6205
+ const auto *RawAddr = DPV.getRawAddress ();
6206
+ CheckDI (
6207
+ isa<ValueAsMetadata>(RawAddr) ||
6208
+ (isa<MDNode>(RawAddr) && !cast<MDNode>(RawAddr)->getNumOperands ()),
6209
+ " invalid #dbg_assign address" , &DPV, DPV.getRawAddress ());
6210
+ CheckDI (DPV.getAddressExpression (),
6211
+ " missing #dbg_assign address expression" , &DPV,
6212
+ DPV.getAddressExpression ());
6213
+ // All of the linked instructions should be in the same function as DPV.
6214
+ for (Instruction *I : at::getAssignmentInsts (&DPV))
6215
+ CheckDI (DPV.getFunction () == I->getFunction (),
6216
+ " inst not in same function as #dbg_assign" , I, &DPV);
6217
+ }
6218
+
6219
+ if (MDNode *N = DPV.getDebugLoc ().getAsMDNode ()) {
6220
+ CheckDI (isa<DILocation>(N), " invalid #dbg_" + Kind + " location" , &DPV, N);
6221
+ visitDILocation (*cast<DILocation>(N));
6222
+ }
6223
+
6224
+ BasicBlock *BB = DPV.getParent ();
6225
+ Function *F = BB ? BB->getParent () : nullptr ;
6226
+
6227
+ // The scopes for variables and !dbg attachments must agree.
6228
+ DILocalVariable *Var = DPV.getVariable ();
6229
+ DILocation *Loc = DPV.getDebugLoc ();
6230
+ CheckDI (Loc, " missing #dbg_" + Kind + " DILocation" , &DPV, BB, F);
6231
+
6232
+ DISubprogram *VarSP = getSubprogram (Var->getRawScope ());
6233
+ DISubprogram *LocSP = getSubprogram (Loc->getRawScope ());
6234
+ if (!VarSP || !LocSP)
6235
+ return ; // Broken scope chains are checked elsewhere.
6236
+
6237
+ CheckDI (VarSP == LocSP,
6238
+ " mismatched subprogram between #dbg_" + Kind +
6239
+ " variable and DILocation" ,
6240
+ &DPV, BB, F, Var, Var->getScope ()->getSubprogram (), Loc,
6241
+ Loc->getScope ()->getSubprogram ());
6242
+
6243
+ // This check is redundant with one in visitLocalVariable().
6244
+ CheckDI (isType (Var->getRawType ()), " invalid type ref" , Var,
6245
+ Var->getRawType ());
6246
+ }
6247
+
6151
6248
void Verifier::visitVPIntrinsic (VPIntrinsic &VPI) {
6152
6249
if (auto *VPCast = dyn_cast<VPCastIntrinsic>(&VPI)) {
6153
6250
auto *RetTy = cast<VectorType>(VPCast->getType ());
0 commit comments