[cfe-commits] r69287 - in /cfe/trunk: lib/CodeGen/CodeGenModule.cpp test/CodeGen/tentative-decls.c

Daniel Dunbar daniel at zuster.org
Thu Apr 16 08:34:15 PDT 2009


Author: ddunbar
Date: Thu Apr 16 10:34:14 2009
New Revision: 69287

URL: http://llvm.org/viewvc/llvm-project?rev=69287&view=rev
Log:
Ensure that the most recent declaration of a tentative definition wins
when generating a common definition.

Modified:
    cfe/trunk/lib/CodeGen/CodeGenModule.cpp
    cfe/trunk/test/CodeGen/tentative-decls.c

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=69287&r1=69286&r2=69287&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Thu Apr 16 10:34:14 2009
@@ -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);
 }
 

Modified: cfe/trunk/test/CodeGen/tentative-decls.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/tentative-decls.c?rev=69287&r1=69286&r2=69287&view=diff

==============================================================================
--- cfe/trunk/test/CodeGen/tentative-decls.c (original)
+++ cfe/trunk/test/CodeGen/tentative-decls.c Thu Apr 16 10:34:14 2009
@@ -25,4 +25,9 @@
   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





More information about the cfe-commits mailing list