diff options
| author | Jordan Rose <jordan_rose@apple.com> | 2012-11-02 23:49:24 +0000 |
|---|---|---|
| committer | Jordan Rose <jordan_rose@apple.com> | 2012-11-02 23:49:24 +0000 |
| commit | 0da674790151c90a60dfa9a20e4209cece8ade7a (patch) | |
| tree | 5a839a17f4d8ddeb0538b4172f2ada7915b79697 /clang/lib/StaticAnalyzer/Core/CheckerContext.cpp | |
| parent | 8ed46b99353f5b427d73aaddb7b0c2e2a0a8f26c (diff) | |
| download | bcm5719-llvm-0da674790151c90a60dfa9a20e4209cece8ade7a.tar.gz bcm5719-llvm-0da674790151c90a60dfa9a20e4209cece8ade7a.zip | |
[analyzer] isCLibraryFunction: check that the function is at TU-scope.
Also, Decls already carry a pointer to the ASTContext, so there's no need
to pass an extra argument to the predicate.
llvm-svn: 167337
Diffstat (limited to 'clang/lib/StaticAnalyzer/Core/CheckerContext.cpp')
| -rw-r--r-- | clang/lib/StaticAnalyzer/Core/CheckerContext.cpp | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/clang/lib/StaticAnalyzer/Core/CheckerContext.cpp b/clang/lib/StaticAnalyzer/Core/CheckerContext.cpp index 0a047d922aa..570ebc02727 100644 --- a/clang/lib/StaticAnalyzer/Core/CheckerContext.cpp +++ b/clang/lib/StaticAnalyzer/Core/CheckerContext.cpp @@ -38,17 +38,12 @@ StringRef CheckerContext::getCalleeName(const FunctionDecl *FunDecl) const { bool CheckerContext::isCLibraryFunction(const FunctionDecl *FD, StringRef Name) { - return isCLibraryFunction(FD, Name, getASTContext()); -} - -bool CheckerContext::isCLibraryFunction(const FunctionDecl *FD, - StringRef Name, ASTContext &Context) { // To avoid false positives (Ex: finding user defined functions with // similar names), only perform fuzzy name matching when it's a builtin. // Using a string compare is slow, we might want to switch on BuiltinID here. unsigned BId = FD->getBuiltinID(); if (BId != 0) { - StringRef BName = Context.BuiltinInfo.GetName(BId); + StringRef BName = FD->getASTContext().BuiltinInfo.GetName(BId); if (BName.find(Name) != StringRef::npos) return true; } @@ -59,6 +54,19 @@ bool CheckerContext::isCLibraryFunction(const FunctionDecl *FD, if (!II) return false; + // Look through 'extern "C"' and anything similar invented in the future. + const DeclContext *DC = FD->getDeclContext(); + while (DC->isTransparentContext()) + DC = DC->getParent(); + + // If this function is in a namespace, it is not a C library function. + if (!DC->isTranslationUnit()) + return false; + + // If this function is not externally visible, it is not a C library function. + if (FD->getLinkage() != ExternalLinkage) + return false; + StringRef FName = II->getName(); if (FName.equals(Name)) return true; |

