summaryrefslogtreecommitdiffstats
path: root/llvm/lib/IR/DebugInfo.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/IR/DebugInfo.cpp')
-rw-r--r--llvm/lib/IR/DebugInfo.cpp17
1 files changed, 17 insertions, 0 deletions
diff --git a/llvm/lib/IR/DebugInfo.cpp b/llvm/lib/IR/DebugInfo.cpp
index 9a7ff062de0..32521b160a2 100644
--- a/llvm/lib/IR/DebugInfo.cpp
+++ b/llvm/lib/IR/DebugInfo.cpp
@@ -426,6 +426,15 @@ static bool fieldIsScopeRef(const MDNode *DbgNode, unsigned Elt) {
return isScopeRef(dyn_cast_or_null<Metadata>(getField(DbgNode, Elt)));
}
+/// \brief Check if a value can be a DescriptorRef.
+static bool isDescriptorRef(const Metadata *MD) {
+ if (!MD)
+ return true;
+ if (auto *S = dyn_cast<MDString>(MD))
+ return !S->getString().empty();
+ return isa<MDNode>(MD);
+}
+
bool DIType::Verify() const {
if (!isType())
return false;
@@ -1463,6 +1472,10 @@ void DIVariable::printExtendedName(raw_ostream &OS) const {
}
}
+template <> DIRef<DIDescriptor>::DIRef(const Metadata *V) : Val(V) {
+ assert(isDescriptorRef(V) &&
+ "DIDescriptorRef should be a MDString or MDNode");
+}
template <> DIRef<DIScope>::DIRef(const Metadata *V) : Val(V) {
assert(isScopeRef(V) && "DIScopeRef should be a MDString or MDNode");
}
@@ -1471,6 +1484,10 @@ template <> DIRef<DIType>::DIRef(const Metadata *V) : Val(V) {
}
template <>
+DIDescriptorRef DIDescriptor::getFieldAs<DIDescriptorRef>(unsigned Elt) const {
+ return DIDescriptorRef(cast_or_null<Metadata>(getField(DbgNode, Elt)));
+}
+template <>
DIScopeRef DIDescriptor::getFieldAs<DIScopeRef>(unsigned Elt) const {
return DIScopeRef(cast_or_null<Metadata>(getField(DbgNode, Elt)));
}
OpenPOWER on IntegriCloud