]> granicus.if.org Git - clang/commitdiff
Ensure that the most recent declaration of a tentative definition wins
authorDaniel Dunbar <daniel@zuster.org>
Thu, 16 Apr 2009 15:34:14 +0000 (15:34 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Thu, 16 Apr 2009 15:34:14 +0000 (15:34 +0000)
when generating a common definition.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@69287 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CodeGenModule.cpp
test/CodeGen/tentative-decls.c

index 81bff667fb90181152502c84f1d9a7edf6b80695..d1d67a11b8aa5cdeb7396eab66d7492769052448 100644 (file)
@@ -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);
 }
 
index 4604f2f4297d972573ab6a97e148571cf8526514..7fb396a5078f89895459397278673543702d4c32 100644 (file)
@@ -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