diff options
author | Fariborz Jahanian <fjahanian@apple.com> | 2010-06-21 16:08:37 +0000 |
---|---|---|
committer | Fariborz Jahanian <fjahanian@apple.com> | 2010-06-21 16:08:37 +0000 |
commit | 2bf6d7b1f7406ca4dfe841d4f6ef4b91dce195e4 (patch) | |
tree | 60117f53e947058fb15d7d4dc7a4616f27d55e02 /lib/AST/Decl.cpp | |
parent | 5bf1bdc2fedb0c29b5fcdb4abc852aa85b4fe26a (diff) |
Fixes a corner case bug whereby declaring and defining an extern variable in a
particular sequence causes its definition to not be generated in the object file.
(fixes radar 8071804).
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@106424 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/AST/Decl.cpp')
-rw-r--r-- | lib/AST/Decl.cpp | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/lib/AST/Decl.cpp b/lib/AST/Decl.cpp index 25687e15c4..c912af878a 100644 --- a/lib/AST/Decl.cpp +++ b/lib/AST/Decl.cpp @@ -701,7 +701,15 @@ VarDecl::DefinitionKind VarDecl::isThisDeclarationADefinition() const { // AST for 'extern "C" int foo;' is annotated with 'extern'. if (hasExternalStorage()) return DeclarationOnly; - + + if (getStorageClassAsWritten() == Extern || + getStorageClassAsWritten() == PrivateExtern) { + for (const VarDecl *PrevVar = getPreviousDeclaration(); + PrevVar; PrevVar = PrevVar->getPreviousDeclaration()) { + if (PrevVar->getLinkage() == InternalLinkage && PrevVar->hasInit()) + return DeclarationOnly; + } + } // C99 6.9.2p2: // A declaration of an object that has file scope without an initializer, // and without a storage class specifier or the scs 'static', constitutes |