diff options
| author | Douglas Gregor <dgregor@apple.com> | 2009-03-02 00:19:53 +0000 |
|---|---|---|
| committer | Douglas Gregor <dgregor@apple.com> | 2009-03-02 00:19:53 +0000 |
| commit | 5a80bd15044647ff15e12bd7b1605d82e2d0cd97 (patch) | |
| tree | fd0d3d411b0366d80cd0daef039eaef2b4f17a11 /clang/lib/AST | |
| parent | a9e981225e050a02c79c68537779b36289d2115b (diff) | |
| download | bcm5719-llvm-5a80bd15044647ff15e12bd7b1605d82e2d0cd97.tar.gz bcm5719-llvm-5a80bd15044647ff15e12bd7b1605d82e2d0cd97.zip | |
Rework the way we find locally-scoped external declarations when we
need them to evaluate redeclarations or call a function that hasn't
already been declared. We now keep a DenseMap of these locally-scoped
declarations so that they are not visible but can be quickly found,
e.g., when we're looking for previous declarations or before we go
ahead and implicitly declare a function that's being called. Fixes
PR3672.
llvm-svn: 65792
Diffstat (limited to 'clang/lib/AST')
| -rw-r--r-- | clang/lib/AST/Decl.cpp | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp index b30b86980f6..1ebfbf79dac 100644 --- a/clang/lib/AST/Decl.cpp +++ b/clang/lib/AST/Decl.cpp @@ -63,6 +63,28 @@ QualType ParmVarDecl::getOriginalType() const { return getType(); } +bool VarDecl::isExternC(ASTContext &Context) const { + if (!Context.getLangOptions().CPlusPlus) + return (getDeclContext()->isTranslationUnit() && + getStorageClass() != Static) || + (getDeclContext()->isFunctionOrMethod() && hasExternalStorage()); + + for (const DeclContext *DC = getDeclContext(); !DC->isTranslationUnit(); + DC = DC->getParent()) { + if (const LinkageSpecDecl *Linkage = dyn_cast<LinkageSpecDecl>(DC)) { + if (Linkage->getLanguage() == LinkageSpecDecl::lang_c) + return getStorageClass() != Static; + + break; + } + + if (DC->isFunctionOrMethod()) + return false; + } + + return false; +} + OriginalParmVarDecl *OriginalParmVarDecl::Create( ASTContext &C, DeclContext *DC, SourceLocation L, IdentifierInfo *Id, @@ -273,6 +295,25 @@ bool FunctionDecl::isMain() const { getIdentifier() && getIdentifier()->isStr("main"); } +bool FunctionDecl::isExternC(ASTContext &Context) const { + // In C, any non-static, non-overloadable function has external + // linkage. + if (!Context.getLangOptions().CPlusPlus) + return getStorageClass() != Static && !getAttr<OverloadableAttr>(); + + for (const DeclContext *DC = getDeclContext(); !DC->isTranslationUnit(); + DC = DC->getParent()) { + if (const LinkageSpecDecl *Linkage = dyn_cast<LinkageSpecDecl>(DC)) { + if (Linkage->getLanguage() == LinkageSpecDecl::lang_c) + return getStorageClass() != Static && !getAttr<OverloadableAttr>(); + + break; + } + } + + return false; +} + /// \brief Returns a value indicating whether this function /// corresponds to a builtin function. /// |

