From 6463ef4caf2fb576d38b1b2e15a29ac9f2abb3e7 Mon Sep 17 00:00:00 2001 From: Daniel Dunbar Date: Thu, 16 Apr 2009 15:34:14 +0000 Subject: [PATCH] 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 --- lib/CodeGen/CodeGenModule.cpp | 8 +++++--- test/CodeGen/tentative-decls.c | 5 +++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp index 81bff667fb..d1d67a11b8 100644 --- a/lib/CodeGen/CodeGenModule.cpp +++ b/lib/CodeGen/CodeGenModule.cpp @@ -424,9 +424,11 @@ void CodeGenModule::EmitDeferred() { EmitGlobalDefinition(D); } - // Emit any tentative definitions. - for (std::vector::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::reverse_iterator + it = TentativeDefinitions.rbegin(), ie = TentativeDefinitions.rend(); + it != ie; ++it) EmitTentativeDefinition(*it); } diff --git a/test/CodeGen/tentative-decls.c b/test/CodeGen/tentative-decls.c index 4604f2f429..7fb396a507 100644 --- a/test/CodeGen/tentative-decls.c +++ b/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 -- 2.40.0