summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--clang/lib/CodeGen/CodeGenModule.cpp8
-rw-r--r--clang/test/CodeGen/tentative-decls.c5
2 files changed, 10 insertions, 3 deletions
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp
index 81bff667fb9..d1d67a11b8a 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -424,9 +424,11 @@ void CodeGenModule::EmitDeferred() {
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);
}
diff --git a/clang/test/CodeGen/tentative-decls.c b/clang/test/CodeGen/tentative-decls.c
index 4604f2f4297..7fb396a5078 100644
--- a/clang/test/CodeGen/tentative-decls.c
+++ b/clang/test/CodeGen/tentative-decls.c
@@ -25,4 +25,9 @@ int *f1() {
return b;
}
+// Check that the most recent tentative definition wins.
+// RUN: grep '@c = common global \[4 x .*\] zeroinitializer' %t &&
+int c[];
+int c[4];
+
// RUN: true
OpenPOWER on IntegriCloud