Ensure that the most recent declaration of a tentative definition wins
when generating a common definition.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@69287 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp
index 81bff66..d1d67a1 100644
--- a/lib/CodeGen/CodeGenModule.cpp
+++ b/lib/CodeGen/CodeGenModule.cpp
@@ -424,9 +424,11 @@
EmitGlobalDefinition(D);
}
- // Emit any tentative definitions.
- for (std::vector<const VarDecl*>::iterator it = TentativeDefinitions.begin(),
- ie = TentativeDefinitions.end(); it != ie; ++it)
+ // Emit any tentative definitions, in reverse order so the most
+ // important (merged) decl will be seen and emitted first.
+ for (std::vector<const VarDecl*>::reverse_iterator
+ it = TentativeDefinitions.rbegin(), ie = TentativeDefinitions.rend();
+ it != ie; ++it)
EmitTentativeDefinition(*it);
}