public:
explicit DIDescriptor(const MDNode *N = nullptr) : DbgNode(N) {}
+ DIDescriptor(const DebugNode *N) : DbgNode(N) {}
MDNode *get() const { return const_cast<MDNode *>(DbgNode); }
operator MDNode *() const { return get(); }
DECLARE_SIMPLIFY_DESCRIPTOR(DIImportedEntity)
#undef DECLARE_SIMPLIFY_DESCRIPTOR
+typedef DebugNodeArray DIArray;
+typedef MDTypeRefArray DITypeArray;
+
/// \brief This is used to represent ranges, for array bounds.
class DISubrange : public DIDescriptor {
public:
int64_t getCount() const { return get()->getCount(); }
};
-/// \brief This descriptor holds an array of nodes with type T.
-template <typename T> class DITypedArray : public DIDescriptor {
-public:
- explicit DITypedArray(const MDNode *N = nullptr) : DIDescriptor(N) {}
- operator MDTuple *() const {
- return const_cast<MDTuple *>(cast_or_null<MDTuple>(DbgNode));
- }
- unsigned getNumElements() const {
- return DbgNode ? DbgNode->getNumOperands() : 0;
- }
- T getElement(unsigned Idx) const { return getFieldAs<T>(Idx); }
-};
-
-typedef DITypedArray<DIDescriptor> DIArray;
-
/// \brief A wrapper for an enumerator (e.g. X and Y in 'enum {X,Y}').
///
/// FIXME: it seems strange that this doesn't have either a reference to the
typedef DIRef<DIDescriptor> DIDescriptorRef;
typedef DIRef<DIScope> DIScopeRef;
typedef DIRef<DIType> DITypeRef;
-typedef DITypedArray<DITypeRef> DITypeArray;
/// \brief A base class for various scopes.
///
return *get();
}
- DITypedArray<DITypeRef> getTypeArray() const {
- return DITypedArray<DITypeRef>(get()->getTypeArray());
- }
+ MDTypeRefArray getTypeArray() const { return get()->getTypeArray(); }
};
/// \brief This is a wrapper for a file.
MDTuple *operator->() const { return const_cast<MDTuple *>(N); }
MDTuple &operator*() const { return *const_cast<MDTuple *>(N); }
- unsigned size() const { return N->getNumOperands(); }
+ // FIXME: Fix callers and remove condition on N.
+ unsigned size() const { return N ? N->getNumOperands() : 0u; }
MDTypeRef operator[](unsigned I) const { return MDTypeRef(N->getOperand(I)); }
class iterator : std::iterator<std::input_iterator_tag, MDTypeRef,
std::ptrdiff_t, void, MDTypeRef> {
- MDNode::op_iterator I;
+ MDNode::op_iterator I = nullptr;
public:
+ iterator() = default;
explicit iterator(MDNode::op_iterator I) : I(I) {}
MDTypeRef operator*() const { return MDTypeRef(*I); }
iterator &operator++() {
bool operator!=(const iterator &X) const { return I != X.I; }
};
- iterator begin() const { return iterator(N->op_begin()); }
- iterator end() const { return iterator(N->op_end()); }
+ // FIXME: Fix callers and remove condition on N.
+ iterator begin() const { return N ? iterator(N->op_begin()) : iterator(); }
+ iterator end() const { return N ? iterator(N->op_end()) : iterator(); }
};
/// \brief Tagged DWARF-like metadata node.
template <class T>
class TypedMDOperandIterator
: std::iterator<std::input_iterator_tag, T *, std::ptrdiff_t, void, T *> {
- MDNode::op_iterator I;
+ MDNode::op_iterator I = nullptr;
public:
+ TypedMDOperandIterator() = default;
explicit TypedMDOperandIterator(MDNode::op_iterator I) : I(I) {}
T *operator*() const { return cast_or_null<T>(*I); }
TypedMDOperandIterator &operator++() {
const MDTuple *N = nullptr;
public:
+ MDTupleTypedArrayWrapper() = default;
MDTupleTypedArrayWrapper(const MDTuple *N) : N(N) {}
operator MDTuple *() const { return const_cast<MDTuple *>(N); }
MDTuple *operator->() const { return const_cast<MDTuple *>(N); }
MDTuple &operator*() const { return *const_cast<MDTuple *>(N); }
- unsigned size() const { return N->getNumOperands(); }
+ // FIXME: Fix callers and remove condition on N.
+ unsigned size() const { return N ? N->getNumOperands() : 0u; }
T *operator[](unsigned I) const { return cast_or_null<T>(N->getOperand(I)); }
+ // FIXME: Fix callers and remove condition on N.
typedef TypedMDOperandIterator<T> iterator;
- iterator begin() const { return iterator(N->op_begin()); }
- iterator end() const { return iterator(N->op_end()); }
+ iterator begin() const { return N ? iterator(N->op_begin()) : iterator(); }
+ iterator end() const { return N ? iterator(N->op_end()) : iterator(); }
};
#define HANDLE_METADATA(CLASS) \
// If we have a single element of null, it is a function that returns void.
// If we have more than one elements and the last one is null, it is a
// variadic function.
- if (FnArgs.getNumElements() > 1 &&
- !FnArgs.getElement(FnArgs.getNumElements() - 1) &&
+ if (FnArgs.size() > 1 && !FnArgs[FnArgs.size() - 1] &&
!includeMinimalInlineScopes())
ScopeDIE.addChild(make_unique<DIE>(dwarf::DW_TAG_unspecified_parameters));
}
assert(SP && "CU's subprogram list contains a non-subprogram");
assert(SP.isDefinition() &&
"CU's subprogram list contains a subprogram declaration");
- DIArray Variables = SP.getVariables();
- if (Variables.getNumElements() == 0)
+ auto Variables = SP->getVariables();
+ if (Variables.size() == 0)
return;
DIE *SPDIE = DU->getAbstractSPDies().lookup(SP);
if (!SPDIE)
SPDIE = getDIE(SP);
assert(SPDIE);
- for (unsigned vi = 0, ve = Variables.getNumElements(); vi != ve; ++vi) {
- DIVariable DV = cast<MDLocalVariable>(Variables.getElement(vi));
+ for (DIVariable DV : Variables) {
DbgVariable NewVar(DV, DIExpression(), DD);
auto VariableDie = constructVariableDIE(NewVar);
applyVariableAttributes(NewVar, *VariableDie);
subType = resolve(DITypeRef(cast<MDDerivedType>(Ty)->getBaseType()));
DIArray Elements(cast<MDCompositeTypeBase>(subType)->getElements());
- for (unsigned i = 0, N = Elements.getNumElements(); i < N; ++i) {
- DIDerivedType DT = cast<MDDerivedTypeBase>(Elements.getElement(i));
+ for (unsigned i = 0, N = Elements.size(); i < N; ++i) {
+ DIDerivedType DT = cast<MDDerivedTypeBase>(Elements[i]);
if (getName() == DT.getName())
return (resolve(DT.getTypeDerivedFrom()));
}
for (MDNode *N : CU_Nodes->operands()) {
DICompileUnit CUNode = cast<MDCompileUnit>(N);
DwarfCompileUnit &CU = constructDwarfCompileUnit(CUNode);
- DIArray ImportedEntities = CUNode.getImportedEntities();
- for (unsigned i = 0, e = ImportedEntities.getNumElements(); i != e; ++i)
- ScopesWithImportedEntities.push_back(std::make_pair(
- cast<MDImportedEntity>(ImportedEntities.getElement(i))->getScope(),
- ImportedEntities.getElement(i)));
+ for (auto *IE : CUNode->getImportedEntities())
+ ScopesWithImportedEntities.push_back(std::make_pair(IE->getScope(), IE));
// Stable sort to preserve the order of appearance of imported entities.
// This is to avoid out-of-order processing of interdependent declarations
// within the same scope, e.g. { namespace A = base; namespace B = A; }
std::stable_sort(ScopesWithImportedEntities.begin(),
ScopesWithImportedEntities.end(), less_first());
- DIArray GVs = CUNode.getGlobalVariables();
- for (unsigned i = 0, e = GVs.getNumElements(); i != e; ++i)
- CU.getOrCreateGlobalVariableDIE(
- cast<MDGlobalVariable>(GVs.getElement(i)));
- DIArray SPs = CUNode.getSubprograms();
- for (unsigned i = 0, e = SPs.getNumElements(); i != e; ++i)
- SPMap.insert(std::make_pair(SPs.getElement(i), &CU));
- DIArray EnumTypes = CUNode.getEnumTypes();
- for (unsigned i = 0, e = EnumTypes.getNumElements(); i != e; ++i) {
- DIType Ty = cast<MDType>(EnumTypes.getElement(i));
+ for (auto *GV : CUNode->getGlobalVariables())
+ CU.getOrCreateGlobalVariableDIE(GV);
+ for (auto *SP : CUNode->getSubprograms())
+ SPMap.insert(std::make_pair(SP, &CU));
+ for (DIType Ty : CUNode->getEnumTypes()) {
// The enum types array by design contains pointers to
// MDNodes rather than DIRefs. Unique them here.
DIType UniqueTy = cast<MDType>(resolve(Ty.getRef()));
CU.getOrCreateTypeDIE(UniqueTy);
}
- DIArray RetainedTypes = CUNode.getRetainedTypes();
- for (unsigned i = 0, e = RetainedTypes.getNumElements(); i != e; ++i) {
- DIType Ty = cast<MDType>(RetainedTypes.getElement(i));
+ for (DIType Ty : CUNode->getRetainedTypes()) {
// The retained types array by design contains pointers to
// MDNodes rather than DIRefs. Unique them here.
DIType UniqueTy = cast<MDType>(resolve(Ty.getRef()));
}
// Emit imported_modules last so that the relevant context is already
// available.
- for (unsigned i = 0, e = ImportedEntities.getNumElements(); i != e; ++i)
- constructAndAddImportedEntityDIE(CU, ImportedEntities.getElement(i));
+ for (auto *IE : CUNode->getImportedEntities())
+ constructAndAddImportedEntityDIE(CU, IE);
}
// Tell MMI that we have debug info.
DwarfCompileUnit *SPCU =
static_cast<DwarfCompileUnit *>(CUMap.lookup(TheCU));
assert(SPCU && "Unable to find Compile Unit!");
- DIArray Subprograms = TheCU.getSubprograms();
- for (unsigned i = 0, e = Subprograms.getNumElements(); i != e; ++i) {
- DISubprogram SP = cast<MDSubprogram>(Subprograms.getElement(i));
+ for (auto *SP : TheCU->getSubprograms()) {
if (ProcessedSPNodes.count(SP) != 0)
continue;
SPCU->collectDeadVariables(SP);
}
// Collect info for variables that were optimized out.
- DIArray Variables = SP.getVariables();
- for (unsigned i = 0, e = Variables.getNumElements(); i != e; ++i) {
- DIVariable DV = cast<MDLocalVariable>(Variables.getElement(i));
+ for (DIVariable DV : SP->getVariables()) {
if (!Processed.insert(DV).second)
continue;
if (LexicalScope *Scope = LScopes.findLexicalScope(DV.get()->getScope())) {
for (LexicalScope *AScope : LScopes.getAbstractScopesList()) {
DISubprogram SP = cast<MDSubprogram>(AScope->getScopeNode());
// Collect info for variables that were optimized out.
- DIArray Variables = SP.getVariables();
- for (unsigned i = 0, e = Variables.getNumElements(); i != e; ++i) {
- DIVariable DV = cast<MDLocalVariable>(Variables.getElement(i));
+ for (DIVariable DV : SP->getVariables()) {
if (!ProcessedVars.insert(DV).second)
continue;
ensureAbstractVariableIsCreated(DV, DV.getContext());
template <typename T> T resolve(DIRef<T> Ref) const {
return Ref.resolve(TypeIdentifierMap);
}
+ template <typename T> T *resolve(TypedDebugNodeRef<T> Ref) const {
+ return Ref.resolve(TypeIdentifierMap);
+ }
/// \brief Return the TypeIdentifierMap.
const DITypeIdentifierMap &getTypeIdentifierMap() const {
DIDerivedType varField;
DIDerivedType forwardingField;
- for (unsigned i = 0, N = Fields.getNumElements(); i < N; ++i) {
- DIDerivedType DT = cast<MDDerivedTypeBase>(Fields.getElement(i));
+ for (unsigned i = 0, N = Fields.size(); i < N; ++i) {
+ DIDerivedType DT = cast<MDDerivedTypeBase>(Fields[i]);
StringRef fieldName = DT.getName();
if (fieldName == "__forwarding")
forwardingField = DT;
/// addTemplateParams - Add template parameters into buffer.
void DwarfUnit::addTemplateParams(DIE &Buffer, DIArray TParams) {
// Add template parameters.
- for (unsigned i = 0, e = TParams.getNumElements(); i != e; ++i) {
- DIDescriptor Element = TParams.getElement(i);
+ for (unsigned i = 0, e = TParams.size(); i != e; ++i) {
+ DIDescriptor Element = TParams[i];
if (auto *TTP = dyn_cast<MDTemplateTypeParameter>(Element))
constructTemplateTypeParameterDIE(Buffer, TTP);
else if (auto *TVP = dyn_cast<MDTemplateValueParameter>(Element))
/// constructSubprogramArguments - Construct function argument DIEs.
void DwarfUnit::constructSubprogramArguments(DIE &Buffer, DITypeArray Args) {
- for (unsigned i = 1, N = Args.getNumElements(); i < N; ++i) {
- DIType Ty = resolve(Args.getElement(i));
+ for (unsigned i = 1, N = Args.size(); i < N; ++i) {
+ DIType Ty = resolve(Args[i]);
if (!Ty) {
assert(i == N-1 && "Unspecified parameter must be the last argument");
createAndAddDIE(dwarf::DW_TAG_unspecified_parameters, Buffer);
break;
case dwarf::DW_TAG_subroutine_type: {
// Add return type. A void return won't have a type.
- DITypeArray Elements(cast<MDSubroutineType>(CTy)->getTypeArray());
- DIType RTy(resolve(Elements.getElement(0)));
- if (RTy)
- addType(Buffer, RTy);
+ auto Elements = cast<MDSubroutineType>(CTy)->getTypeArray();
+ if (Elements.size())
+ if (auto RTy = resolve(Elements[0]))
+ addType(Buffer, RTy);
bool isPrototyped = true;
- if (Elements.getNumElements() == 2 &&
- !Elements.getElement(1))
+ if (Elements.size() == 2 && !Elements[1])
isPrototyped = false;
constructSubprogramArguments(Buffer, Elements);
case dwarf::DW_TAG_class_type: {
// Add elements to structure type.
DIArray Elements = CTy.getElements();
- for (unsigned i = 0, N = Elements.getNumElements(); i < N; ++i) {
- DIDescriptor Element = Elements.getElement(i);
+ for (unsigned i = 0, N = Elements.size(); i < N; ++i) {
+ DIDescriptor Element = Elements[i];
if (!Element)
continue;
if (auto *SP = dyn_cast<MDSubprogram>(Element))
addString(ParamDIE, dwarf::DW_AT_GNU_template_name,
cast<MDString>(Val)->getString());
} else if (VP.getTag() == dwarf::DW_TAG_GNU_template_parameter_pack) {
- assert(isa<MDNode>(Val));
- DIArray A(cast<MDNode>(Val));
- addTemplateParams(ParamDIE, A);
+ addTemplateParams(ParamDIE, cast<MDTuple>(Val));
}
}
}
assert(SPTy.getTag() == dwarf::DW_TAG_subroutine_type &&
"the type of a subprogram should be a subroutine");
- DITypeArray Args = SPTy.getTypeArray();
+ auto Args = SPTy.getTypeArray();
// Add a return type. If this is a type like a C/C++ void type we don't add a
// return type.
- if (resolve(Args.getElement(0)))
- addType(SPDie, DIType(resolve(Args.getElement(0))));
+ if (Args.size())
+ if (auto Ty = resolve(Args[0]))
+ addType(SPDie, Ty);
unsigned VK = SP.getVirtuality();
if (VK) {
// Add subranges to array type.
DIArray Elements = CTy.getElements();
- for (unsigned i = 0, N = Elements.getNumElements(); i < N; ++i) {
- DIDescriptor Element = Elements.getElement(i);
+ for (unsigned i = 0, N = Elements.size(); i < N; ++i) {
+ DIDescriptor Element = Elements[i];
if (Element.getTag() == dwarf::DW_TAG_subrange_type)
constructSubrangeDIE(Buffer, cast<MDSubrange>(Element), IdxTy);
}
DIArray Elements = CTy.getElements();
// Add enumerators to enumeration type.
- for (unsigned i = 0, N = Elements.getNumElements(); i < N; ++i) {
- DIEnumerator Enum = dyn_cast_or_null<MDEnumerator>(Elements.getElement(i));
+ for (unsigned i = 0, N = Elements.size(); i < N; ++i) {
+ DIEnumerator Enum = dyn_cast_or_null<MDEnumerator>(Elements[i]);
if (Enum) {
DIE &Enumerator = createAndAddDIE(dwarf::DW_TAG_enumerator, Buffer);
StringRef Name = Enum.getName();
template <typename T> T resolve(DIRef<T> Ref) const {
return DD->resolve(Ref);
}
+ template <typename T> T *resolve(TypedDebugNodeRef<T> Ref) const {
+ return DD->resolve(Ref);
+ }
private:
/// constructTypeDIE - Construct basic type die from DIBasicType.
DIArray SPs = getOrCreateArray(AllSubprograms);
TempSubprograms->replaceAllUsesWith(SPs);
- for (unsigned i = 0, e = SPs.getNumElements(); i != e; ++i) {
- DISubprogram SP = cast<MDSubprogram>(SPs.getElement(i));
+ for (unsigned i = 0, e = SPs.size(); i != e; ++i) {
+ DISubprogram SP = cast<MDSubprogram>(SPs[i]);
if (MDNode *Temp = SP.getVariablesNodes()) {
const auto &PV = PreservedVariables.lookup(SP);
SmallVector<Metadata *, 4> Variables(PV.begin(), PV.end());
{
TypedTrackingMDRef<MDCompositeTypeBase> N(T);
if (Elements)
- N->replaceElements(cast<MDTuple>(Elements.get()));
+ N->replaceElements(Elements);
if (TParams)
- N->replaceTemplateParams(cast<MDTuple>(TParams.get()));
+ N->replaceTemplateParams(MDTemplateParameterArray(TParams));
T = N.get();
}
}
void DICompileUnit::replaceSubprograms(DIArray Subprograms) {
- get()->replaceSubprograms(cast_or_null<MDTuple>(Subprograms.get()));
+ get()->replaceSubprograms(Subprograms);
}
void DICompileUnit::replaceGlobalVariables(DIArray GlobalVariables) {
- get()->replaceGlobalVariables(cast_or_null<MDTuple>(GlobalVariables.get()));
+ get()->replaceGlobalVariables(GlobalVariables);
}
DILocation DILocation::copyWithNewScope(LLVMContext &Ctx,
for (unsigned CUi = 0, CUe = CU_Nodes->getNumOperands(); CUi != CUe; ++CUi) {
DICompileUnit CU = cast<MDCompileUnit>(CU_Nodes->getOperand(CUi));
DIArray Retain = CU.getRetainedTypes();
- for (unsigned Ti = 0, Te = Retain.getNumElements(); Ti != Te; ++Ti) {
- if (!isa<MDCompositeType>(Retain.getElement(Ti)))
+ for (unsigned Ti = 0, Te = Retain.size(); Ti != Te; ++Ti) {
+ if (!isa<MDCompositeType>(Retain[Ti]))
continue;
- DICompositeType Ty = cast<MDCompositeType>(Retain.getElement(Ti));
+ DICompositeType Ty = cast<MDCompositeType>(Retain[Ti]);
if (MDString *TypeId = Ty.getIdentifier()) {
// Definition has priority over declaration.
// Try to insert (TypeId, Ty) to Map.
for (unsigned i = 0, e = CU_Nodes->getNumOperands(); i != e; ++i) {
DICompileUnit CU = cast<MDCompileUnit>(CU_Nodes->getOperand(i));
addCompileUnit(CU);
- DIArray GVs = CU.getGlobalVariables();
- for (unsigned i = 0, e = GVs.getNumElements(); i != e; ++i) {
- DIGlobalVariable DIG = cast<MDGlobalVariable>(GVs.getElement(i));
+ for (DIGlobalVariable DIG : CU->getGlobalVariables()) {
if (addGlobalVariable(DIG)) {
processScope(DIG.getContext());
processType(DIG.getType().resolve(TypeIdentifierMap));
}
}
- DIArray SPs = CU.getSubprograms();
- for (unsigned i = 0, e = SPs.getNumElements(); i != e; ++i)
- processSubprogram(cast<MDSubprogram>(SPs.getElement(i)));
- DIArray EnumTypes = CU.getEnumTypes();
- for (unsigned i = 0, e = EnumTypes.getNumElements(); i != e; ++i)
- processType(cast<MDType>(EnumTypes.getElement(i)));
- DIArray RetainedTypes = CU.getRetainedTypes();
- for (unsigned i = 0, e = RetainedTypes.getNumElements(); i != e; ++i)
- processType(cast<MDType>(RetainedTypes.getElement(i)));
- DIArray Imports = CU.getImportedEntities();
- for (unsigned i = 0, e = Imports.getNumElements(); i != e; ++i) {
- DIImportedEntity Import = cast<MDImportedEntity>(Imports.getElement(i));
+ for (auto *SP : CU->getSubprograms())
+ processSubprogram(SP);
+ for (auto *ET : CU->getEnumTypes())
+ processType(ET);
+ for (auto *RT : CU->getRetainedTypes())
+ processType(RT);
+ for (DIImportedEntity Import : CU->getImportedEntities()) {
DIDescriptor Entity = Import.getEntity().resolve(TypeIdentifierMap);
if (auto *T = dyn_cast<MDType>(Entity))
processType(T);
if (DICompositeType DCT = dyn_cast<MDCompositeTypeBase>(DT)) {
processType(DCT.getTypeDerivedFrom().resolve(TypeIdentifierMap));
if (DISubroutineType ST = dyn_cast<MDSubroutineType>(DCT)) {
- DITypeArray DTA = ST.getTypeArray();
- for (unsigned i = 0, e = DTA.getNumElements(); i != e; ++i)
- processType(DTA.getElement(i).resolve(TypeIdentifierMap));
+ for (MDTypeRef Ref : ST->getTypeArray())
+ processType(Ref.resolve(TypeIdentifierMap));
return;
}
- DIArray DA = DCT.getElements();
- for (unsigned i = 0, e = DA.getNumElements(); i != e; ++i) {
- DIDescriptor D = DA.getElement(i);
+ for (Metadata *D : DCT->getElements()->operands()) {
if (DIType T = dyn_cast<MDType>(D))
processType(T);
else if (DISubprogram SP = dyn_cast<MDSubprogram>(D))
return;
processScope(SP.getContext().resolve(TypeIdentifierMap));
processType(SP.getType());
- DIArray TParams = SP.getTemplateParams();
- for (unsigned I = 0, E = TParams.getNumElements(); I != E; ++I) {
- DIDescriptor Element = TParams.getElement(I);
+ for (auto *Element : SP.getTemplateParams()) {
if (DITemplateTypeParameter TType =
dyn_cast<MDTemplateTypeParameter>(Element)) {
processType(TType.getType().resolve(TypeIdentifierMap));
for (MDNode *N : CU_Nodes->operands()) {
DICompileUnit CUNode = cast<MDCompileUnit>(N);
- DIArray SPs = CUNode.getSubprograms();
- for (unsigned i = 0, e = SPs.getNumElements(); i != e; ++i) {
- DISubprogram SP = cast<MDSubprogram>(SPs.getElement(i));
+ for (DISubprogram SP : CUNode->getSubprograms()) {
if (Function *F = SP.getFunction())
R.insert(std::make_pair(F, SP));
}
raw_fd_ostream out(mangleName(CU, "gcno"), EC, sys::fs::F_None);
std::string EdgeDestinations;
- DIArray SPs = CU.getSubprograms();
unsigned FunctionIdent = 0;
- for (unsigned i = 0, e = SPs.getNumElements(); i != e; ++i) {
- DISubprogram SP = cast_or_null<MDSubprogram>(SPs.getElement(i));
- if (!SP)
- continue;
-
+ for (DISubprogram SP : CU->getSubprograms()) {
Function *F = SP.getFunction();
if (!F) continue;
if (!functionHasLines(F)) continue;
bool InsertIndCounterIncrCode = false;
for (unsigned i = 0, e = CU_Nodes->getNumOperands(); i != e; ++i) {
DICompileUnit CU = cast<MDCompileUnit>(CU_Nodes->getOperand(i));
- DIArray SPs = CU.getSubprograms();
SmallVector<std::pair<GlobalVariable *, MDNode *>, 8> CountersBySP;
- for (unsigned i = 0, e = SPs.getNumElements(); i != e; ++i) {
- DISubprogram SP = cast_or_null<MDSubprogram>(SPs.getElement(i));
- if (!SP)
- continue;
+ for (DISubprogram SP : CU->getSubprograms()) {
Function *F = SP.getFunction();
if (!F) continue;
if (!functionHasLines(F)) continue;
// Add an operand to an existing MDNode. The new operand will be added at the
// back of the operand list.
-static void AddOperand(DICompileUnit CU, DIArray SPs, Metadata *NewSP) {
+static void AddOperand(DICompileUnit CU, MDSubprogramArray SPs, Metadata *NewSP) {
SmallVector<Metadata *, 16> NewSPs;
- NewSPs.reserve(SPs->getNumOperands() + 1);
- for (unsigned I = 0, E = SPs->getNumOperands(); I != E; ++I)
- NewSPs.push_back(SPs->getOperand(I));
+ NewSPs.reserve(SPs.size() + 1);
+ for (auto *SP : SPs)
+ NewSPs.push_back(SP);
NewSPs.push_back(NewSP);
CU.replaceSubprograms(DIArray(MDNode::get(CU->getContext(), NewSPs)));
}
cast<MDSubprogram>(MapMetadata(OldSubprogramMDNode, VMap));
for (DICompileUnit CU : Finder.compile_units()) {
- DIArray Subprograms(CU.getSubprograms());
-
+ auto Subprograms = CU->getSubprograms();
// If the compile unit's function list contains the old function, it should
// also contain the new one.
- for (unsigned i = 0; i < Subprograms.getNumElements(); i++) {
- if ((MDNode*)Subprograms.getElement(i) == OldSubprogramMDNode) {
+ for (auto *SP : Subprograms) {
+ if (SP == OldSubprogramMDNode) {
AddOperand(CU, Subprograms, NewSubprogram);
break;
}
DICompileUnit CU1 = cast<MDCompileUnit>(*Iter);
Iter++;
DICompileUnit CU2 = cast<MDCompileUnit>(*Iter);
- EXPECT_TRUE(CU1.getSubprograms().getNumElements() == 0
- || CU2.getSubprograms().getNumElements() == 0);
+ EXPECT_TRUE(CU1.getSubprograms().size() == 0 ||
+ CU2.getSubprograms().size() == 0);
}
// Test that instructions in the old function still belong to it in the