return getNodeField(DbgNode, DIVariableInlinedAtIndex);
}
-/// Return the size reported by the variable's type.
+/// \brief Return the size reported by the variable's type.
unsigned DIVariable::getSizeInBits(const DITypeIdentifierMap &Map) {
DIType Ty = getType().resolve(Map);
// Follow derived types until we reach a type that
return DbgNode->getNumOperands() == 3 && getNumHeaderFields() == 6;
}
-/// Check if a field at position Elt of a MDNode is a MDNode.
+/// \brief Check if a field at position Elt of a MDNode is a MDNode.
+///
/// We currently allow an empty string and an integer.
/// But we don't allow a non-empty string in a MDNode field.
static bool fieldIsMDNode(const MDNode *DbgNode, unsigned Elt) {
return true;
}
-/// Check if a field at position Elt of a MDNode is a MDString.
+/// \brief Check if a field at position Elt of a MDNode is a MDString.
static bool fieldIsMDString(const MDNode *DbgNode, unsigned Elt) {
Value *Fld = getField(DbgNode, Elt);
return !Fld || isa<MDString>(Fld);
}
-/// Check if a value can be a reference to a type.
+/// \brief Check if a value can be a reference to a type.
static bool isTypeRef(const Value *Val) {
return !Val ||
(isa<MDString>(Val) && !cast<MDString>(Val)->getString().empty()) ||
(isa<MDNode>(Val) && DIType(cast<MDNode>(Val)).isType());
}
-/// Check if a field at position Elt of a MDNode can be a reference to a type.
+/// \brief Check if referenced field might be a type.
static bool fieldIsTypeRef(const MDNode *DbgNode, unsigned Elt) {
Value *Fld = getField(DbgNode, Elt);
return isTypeRef(Fld);
}
-/// Check if a value can be a ScopeRef.
+/// \brief Check if a value can be a ScopeRef.
static bool isScopeRef(const Value *Val) {
return !Val ||
(isa<MDString>(Val) && !cast<MDString>(Val)->getString().empty()) ||
isa<MDNode>(Val);
}
-/// Check if a field at position Elt of a MDNode can be a ScopeRef.
+/// \brief Check if a field at position Elt of a MDNode can be a ScopeRef.
static bool fieldIsScopeRef(const MDNode *DbgNode, unsigned Elt) {
Value *Fld = getField(DbgNode, Elt);
return isScopeRef(Fld);
return false;
}
-/// Verify - Verify that a basic type descriptor is well formed.
bool DIBasicType::Verify() const {
return isBasicType() && DbgNode->getNumOperands() == 3 &&
getNumHeaderFields() == 8;
return DISubprogram();
}
+DISubprogram llvm::getDISubprogram(const Function *F) {
+ // We look for the first instr that has a debug annotation leading back to F.
+ for (auto &BB : *F) {
+ auto Inst = std::find_if(BB.begin(), BB.end(), [](const Instruction &Inst) {
+ return !Inst.getDebugLoc().isUnknown();
+ });
+ if (Inst == BB.end())
+ continue;
+ DebugLoc DLoc = Inst->getDebugLoc();
+ const MDNode *Scope = DLoc.getScopeNode(F->getParent()->getContext());
+ DISubprogram Subprogram = getDISubprogram(Scope);
+ return Subprogram.describes(F) ? Subprogram : DISubprogram();
+ }
+
+ return DISubprogram();
+}
+
DICompositeType llvm::getDICompositeType(DIType T) {
if (T.isCompositeType())
return DICompositeType(T);