diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp index a1f5e5d208ffb..47a93d624dfa9 100644 --- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp @@ -2444,11 +2444,14 @@ bool AsmPrinter::doFinalization(Module &M) { // we can conditionalize accesses based on whether or not it is nullptr. MF = nullptr; - for (GlobalVariable &G : make_early_inc_range(M.globals())) { + std::vector GlobalsToTag; + for (GlobalVariable &G : M.globals()) { if (G.isDeclaration() || !G.isTagged()) continue; - tagGlobalDefinition(M, &G); + GlobalsToTag.push_back(&G); } + for (GlobalVariable *G : GlobalsToTag) + tagGlobalDefinition(M, G); // Gather all GOT equivalent globals in the module. We really need two // passes over the globals: one to compute and another to avoid its emission