diff options
| author | Daniel Dunbar <daniel@zuster.org> | 2009-04-16 15:34:14 +0000 | 
|---|---|---|
| committer | Daniel Dunbar <daniel@zuster.org> | 2009-04-16 15:34:14 +0000 | 
| commit | 426b5cf16ae97e1cb9c4b459861e35c88908d50e (patch) | |
| tree | 21eff07b7d190172bddb71b1e82afc74cbb239af | |
| parent | 9ac4390bf42fcb0faeda08153912c6990b79cb1a (diff) | |
| download | bcm5719-llvm-426b5cf16ae97e1cb9c4b459861e35c88908d50e.tar.gz bcm5719-llvm-426b5cf16ae97e1cb9c4b459861e35c88908d50e.zip  | |
Ensure that the most recent declaration of a tentative definition wins
when generating a common definition.
llvm-svn: 69287
| -rw-r--r-- | clang/lib/CodeGen/CodeGenModule.cpp | 8 | ||||
| -rw-r--r-- | clang/test/CodeGen/tentative-decls.c | 5 | 
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  | 

