summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>2015-04-15 22:15:46 +0000
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>2015-04-15 22:15:46 +0000
commitf17f34e42bbac229b51d67f989684d5cfc43a0c5 (patch)
tree0e934a20daa4f82c35070acd5a23f6fc632c3555 /llvm/lib
parent7f5015a9cc0c6c2f6b16ecd6ac69ae898effa8de (diff)
downloadbcm5719-llvm-f17f34e42bbac229b51d67f989684d5cfc43a0c5.tar.gz
bcm5719-llvm-f17f34e42bbac229b51d67f989684d5cfc43a0c5.zip
Verifier: Check that @llvm.dbg.* intrinsics have a !dbg attachment
Before we start to rely on valid `!dbg` attachments, add a check to the verifier that `@llvm.dbg.*` intrinsics always have one. Also check that the `scope:` fields point at the same `MDSubprogram`. This is in the context of PR22778. The check that the `inlinedAt:` fields agree has baked for a while (since r234021), so I'll kill [1] the `MDLocalVariable::getInlinedAt()` field soon. [1]: http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20150330/269387.html Unfortunately, that means it's impossible to keep the current `Verifier` checks, which rely on comparing `inlinedAt:` fields. We'll be able to keep the checks I'm adding here. If this breaks your out-of-tree testcases, the upgrade script (add-dbg-to-intrinsics.sh) attached to PR22778 that I used for r235040 might fix them for you. llvm-svn: 235048
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/IR/Verifier.cpp42
1 files changed, 38 insertions, 4 deletions
diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index 2034f8b54f8..3df885ac8f9 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -3361,6 +3361,25 @@ void Verifier::visitIntrinsicFunctionCall(Intrinsic::ID ID, CallInst &CI) {
};
}
+/// \brief Carefully grab the subprogram from a local scope.
+///
+/// This carefully grabs the subprogram from a local scope, avoiding the
+/// built-in assertions that would typically fire.
+static MDSubprogram *getSubprogram(Metadata *LocalScope) {
+ if (!LocalScope)
+ return nullptr;
+
+ if (auto *SP = dyn_cast<MDSubprogram>(LocalScope))
+ return SP;
+
+ if (auto *LB = dyn_cast<MDLexicalBlockBase>(LocalScope))
+ return getSubprogram(LB->getRawScope());
+
+ // Just return null; broken scope chains are checked elsewhere.
+ assert(!isa<MDLocalScope>(LocalScope) && "Unknown type of local scope");
+ return nullptr;
+}
+
template <class DbgIntrinsicTy>
void Verifier::visitDbgIntrinsic(StringRef Kind, DbgIntrinsicTy &DII) {
auto *MD = cast<MetadataAsValue>(DII.getArgOperand(0))->getMetadata();
@@ -3379,14 +3398,29 @@ void Verifier::visitDbgIntrinsic(StringRef Kind, DbgIntrinsicTy &DII) {
if (!isa<MDLocation>(N))
return;
+ BasicBlock *BB = DII.getParent();
+ Function *F = BB ? BB->getParent() : nullptr;
+
// The inlined-at attachments for variables and !dbg attachments must agree.
MDLocalVariable *Var = DII.getVariable();
MDLocation *VarIA = Var->getInlinedAt();
MDLocation *Loc = DII.getDebugLoc();
- MDLocation *LocIA = Loc ? Loc->getInlinedAt() : nullptr;
- BasicBlock *BB = DII.getParent();
- Assert(VarIA == LocIA, "mismatched variable and !dbg inlined-at", &DII, BB,
- BB ? BB->getParent() : nullptr, Var, VarIA, Loc, LocIA);
+ Assert(Loc, "llvm.dbg." + Kind + " intrinsic requires a !dbg attachment",
+ &DII, BB, F);
+
+ MDLocation *LocIA = Loc->getInlinedAt();
+ Assert(VarIA == LocIA, "mismatched variable and !dbg inlined-at", &DII, BB, F,
+ Var, VarIA, Loc, LocIA);
+
+ MDSubprogram *VarSP = getSubprogram(Var->getRawScope());
+ MDSubprogram *LocSP = getSubprogram(Loc->getRawScope());
+ if (!VarSP || !LocSP)
+ return; // Broken scope chains are checked elsewhere.
+
+ Assert(VarSP == LocSP, "mismatched subprogram between llvm.dbg." + Kind +
+ " variable and !dbg attachment",
+ &DII, BB, F, Var, Var->getScope()->getSubprogram(), Loc,
+ Loc->getScope()->getSubprogram());
}
template <class MapTy>
OpenPOWER on IntegriCloud