@@ -597,6 +597,7 @@ class Verifier : public InstVisitor<Verifier>, VerifierSupport {
597
597
void visitIntrinsicCall (Intrinsic::ID ID, CallBase &Call);
598
598
void visitConstrainedFPIntrinsic (ConstrainedFPIntrinsic &FPI);
599
599
void visitVPIntrinsic (VPIntrinsic &VPI);
600
+ void visitDbgIntrinsic (StringRef Kind, DbgVariableIntrinsic &DII);
600
601
void visitDbgLabelIntrinsic (StringRef Kind, DbgLabelInst &DLI);
601
602
void visitAtomicCmpXchgInst (AtomicCmpXchgInst &CXI);
602
603
void visitAtomicRMWInst (AtomicRMWInst &RMWI);
@@ -635,12 +636,15 @@ class Verifier : public InstVisitor<Verifier>, VerifierSupport {
635
636
void verifyFrameRecoverIndices ();
636
637
void verifySiblingFuncletUnwinds ();
637
638
639
+ void verifyFragmentExpression (const DbgVariableIntrinsic &I);
638
640
void verifyFragmentExpression (const DbgVariableRecord &I);
639
641
template <typename ValueOrMetadata>
640
642
void verifyFragmentExpression (const DIVariable &V,
641
643
DIExpression::FragmentInfo Fragment,
642
644
ValueOrMetadata *Desc);
645
+ void verifyFnArgs (const DbgVariableIntrinsic &I);
643
646
void verifyFnArgs (const DbgVariableRecord &DVR);
647
+ void verifyNotEntryValue (const DbgVariableIntrinsic &I);
644
648
void verifyNotEntryValue (const DbgVariableRecord &I);
645
649
646
650
// / Module-level debug info verification...
@@ -5509,6 +5513,11 @@ void Verifier::visitInstruction(Instruction &I) {
5509
5513
}
5510
5514
}
5511
5515
5516
+ if (auto *DII = dyn_cast<DbgVariableIntrinsic>(&I)) {
5517
+ verifyFragmentExpression (*DII);
5518
+ verifyNotEntryValue (*DII);
5519
+ }
5520
+
5512
5521
SmallVector<std::pair<unsigned , MDNode *>, 4 > MDs;
5513
5522
I.getAllMetadata (MDs);
5514
5523
for (auto Attachment : MDs) {
@@ -5713,14 +5722,18 @@ void Verifier::visitIntrinsicCall(Intrinsic::ID ID, CallBase &Call) {
5713
5722
visitConstrainedFPIntrinsic (cast<ConstrainedFPIntrinsic>(Call));
5714
5723
break ;
5715
5724
case Intrinsic::dbg_declare: // llvm.dbg.declare
5716
- case Intrinsic::dbg_value: // llvm.dbg.value
5717
- case Intrinsic::dbg_assign: // llvm.dbg.assign
5718
- case Intrinsic::dbg_label: // llvm.dbg.label
5719
- // We no longer interpret debug intrinsics (the old variable-location
5720
- // design). They're meaningless as far as LLVM is concerned we could make
5721
- // it an error for them to appear, but it's possible we'll have users
5722
- // converting back to intrinsics for the forseeable future (such as DXIL),
5723
- // so tolerate their existance.
5725
+ Check (isa<MetadataAsValue>(Call.getArgOperand (0 )),
5726
+ " invalid llvm.dbg.declare intrinsic call 1" , Call);
5727
+ visitDbgIntrinsic (" declare" , cast<DbgVariableIntrinsic>(Call));
5728
+ break ;
5729
+ case Intrinsic::dbg_value: // llvm.dbg.value
5730
+ visitDbgIntrinsic (" value" , cast<DbgVariableIntrinsic>(Call));
5731
+ break ;
5732
+ case Intrinsic::dbg_assign: // llvm.dbg.assign
5733
+ visitDbgIntrinsic (" assign" , cast<DbgVariableIntrinsic>(Call));
5734
+ break ;
5735
+ case Intrinsic::dbg_label: // llvm.dbg.label
5736
+ visitDbgLabelIntrinsic (" label" , cast<DbgLabelInst>(Call));
5724
5737
break ;
5725
5738
case Intrinsic::memcpy:
5726
5739
case Intrinsic::memcpy_inline:
@@ -7136,7 +7149,6 @@ void Verifier::visitConstrainedFPIntrinsic(ConstrainedFPIntrinsic &FPI) {
7136
7149
}
7137
7150
}
7138
7151
7139
- <<<<<<< HEAD
7140
7152
void Verifier::visitDbgIntrinsic (StringRef Kind, DbgVariableIntrinsic &DII) {
7141
7153
auto *MD = DII.getRawLocation ();
7142
7154
CheckDI (isa<ValueAsMetadata>(MD) || isa<DIArgList>(MD) ||
@@ -7262,8 +7274,6 @@ void Verifier::verifyFragmentExpression(const DbgVariableIntrinsic &I) {
7262
7274
7263
7275
verifyFragmentExpression (*V, *Fragment, &I);
7264
7276
}
7265
- =======
7266
- >>>>>>> 7caa0c9a55b3
7267
7277
void Verifier::verifyFragmentExpression (const DbgVariableRecord &DVR) {
7268
7278
DILocalVariable *V = dyn_cast_or_null<DILocalVariable>(DVR.getRawVariable ());
7269
7279
DIExpression *E = dyn_cast_or_null<DIExpression>(DVR.getRawExpression ());
@@ -7309,6 +7319,34 @@ void Verifier::verifyFragmentExpression(const DIVariable &V,
7309
7319
CheckDI (MSpace <= dwarf::DW_MSPACE_LLVM_hi_user, " invalid memory space" , &V);
7310
7320
}
7311
7321
7322
+ void Verifier::verifyFnArgs (const DbgVariableIntrinsic &I) {
7323
+ // This function does not take the scope of noninlined function arguments into
7324
+ // account. Don't run it if current function is nodebug, because it may
7325
+ // contain inlined debug intrinsics.
7326
+ if (!HasDebugInfo)
7327
+ return ;
7328
+
7329
+ // For performance reasons only check non-inlined ones.
7330
+ if (I.getDebugLoc ()->getInlinedAt ())
7331
+ return ;
7332
+
7333
+ DILocalVariable *Var = I.getVariable ();
7334
+ CheckDI (Var, " dbg intrinsic without variable" );
7335
+
7336
+ unsigned ArgNo = Var->getArg ();
7337
+ if (!ArgNo)
7338
+ return ;
7339
+
7340
+ // Verify there are no duplicate function argument debug info entries.
7341
+ // These will cause hard-to-debug assertions in the DWARF backend.
7342
+ if (DebugFnArgs.size () < ArgNo)
7343
+ DebugFnArgs.resize (ArgNo, nullptr );
7344
+
7345
+ auto *Prev = DebugFnArgs[ArgNo - 1 ];
7346
+ DebugFnArgs[ArgNo - 1 ] = Var;
7347
+ CheckDI (!Prev || (Prev == Var), " conflicting debug info for argument" , &I,
7348
+ Prev, Var);
7349
+ }
7312
7350
void Verifier::verifyFnArgs (const DbgVariableRecord &DVR) {
7313
7351
// This function does not take the scope of noninlined function arguments into
7314
7352
// account. Don't run it if current function is nodebug, because it may
@@ -7338,6 +7376,29 @@ void Verifier::verifyFnArgs(const DbgVariableRecord &DVR) {
7338
7376
Prev, Var);
7339
7377
}
7340
7378
7379
+ void Verifier::verifyNotEntryValue (const DbgVariableIntrinsic &I) {
7380
+ DIExpression *E = dyn_cast_or_null<DIExpression>(I.getRawExpression ());
7381
+
7382
+ // We don't know whether this intrinsic verified correctly.
7383
+ if (!E || !E->isValid ())
7384
+ return ;
7385
+
7386
+ if (isa<ValueAsMetadata>(I.getRawLocation ())) {
7387
+ Value *VarValue = I.getVariableLocationOp (0 );
7388
+ if (isa<UndefValue>(VarValue) || isa<PoisonValue>(VarValue))
7389
+ return ;
7390
+ // We allow EntryValues for swift async arguments, as they have an
7391
+ // ABI-guarantee to be turned into a specific register.
7392
+ if (auto *ArgLoc = dyn_cast_or_null<Argument>(VarValue);
7393
+ ArgLoc && ArgLoc->hasAttribute (Attribute::SwiftAsync))
7394
+ return ;
7395
+ }
7396
+
7397
+ CheckDI (!E->isEntryValue (),
7398
+ " Entry values are only allowed in MIR unless they target a "
7399
+ " swiftasync Argument" ,
7400
+ &I);
7401
+ }
7341
7402
void Verifier::verifyNotEntryValue (const DbgVariableRecord &DVR) {
7342
7403
DIExpression *E = dyn_cast_or_null<DIExpression>(DVR.getRawExpression ());
7343
7404
0 commit comments