diff options
author | George Karpenkov <ekarpenkov@apple.com> | 2018-03-23 00:16:03 +0000 |
---|---|---|
committer | George Karpenkov <ekarpenkov@apple.com> | 2018-03-23 00:16:03 +0000 |
commit | 2301c5ab4dfda7e2f278971e183dc4b58990f18a (patch) | |
tree | 9976bc834318bc934bfa2975fd2794e8db3a298d /clang/lib/StaticAnalyzer/Core/CheckerHelpers.cpp | |
parent | 628920b460a48ca58b373035333b2899ee0114d3 (diff) | |
download | bcm5719-llvm-2301c5ab4dfda7e2f278971e183dc4b58990f18a.tar.gz bcm5719-llvm-2301c5ab4dfda7e2f278971e183dc4b58990f18a.zip |
[analyzer] Trust _Nonnull annotations for system framework
Changes the analyzer to believe that methods annotated with _Nonnull
from system frameworks indeed return non null objects.
Local methods with such annotation are still distrusted.
rdar://24291919
Differential Revision: https://reviews.llvm.org/D44341
llvm-svn: 328282
Diffstat (limited to 'clang/lib/StaticAnalyzer/Core/CheckerHelpers.cpp')
-rw-r--r-- | clang/lib/StaticAnalyzer/Core/CheckerHelpers.cpp | 29 |
1 files changed, 24 insertions, 5 deletions
diff --git a/clang/lib/StaticAnalyzer/Core/CheckerHelpers.cpp b/clang/lib/StaticAnalyzer/Core/CheckerHelpers.cpp index ed41914ebd0..b9facffcc8b 100644 --- a/clang/lib/StaticAnalyzer/Core/CheckerHelpers.cpp +++ b/clang/lib/StaticAnalyzer/Core/CheckerHelpers.cpp @@ -15,8 +15,12 @@ #include "clang/AST/Decl.h" #include "clang/AST/Expr.h" +namespace clang { + +namespace ento { + // Recursively find any substatements containing macros -bool clang::ento::containsMacro(const Stmt *S) { +bool containsMacro(const Stmt *S) { if (S->getLocStart().isMacroID()) return true; @@ -31,7 +35,7 @@ bool clang::ento::containsMacro(const Stmt *S) { } // Recursively find any substatements containing enum constants -bool clang::ento::containsEnum(const Stmt *S) { +bool containsEnum(const Stmt *S) { const DeclRefExpr *DR = dyn_cast<DeclRefExpr>(S); if (DR && isa<EnumConstantDecl>(DR->getDecl())) @@ -45,7 +49,7 @@ bool clang::ento::containsEnum(const Stmt *S) { } // Recursively find any substatements containing static vars -bool clang::ento::containsStaticLocal(const Stmt *S) { +bool containsStaticLocal(const Stmt *S) { const DeclRefExpr *DR = dyn_cast<DeclRefExpr>(S); if (DR) @@ -61,7 +65,7 @@ bool clang::ento::containsStaticLocal(const Stmt *S) { } // Recursively find any substatements containing __builtin_offsetof -bool clang::ento::containsBuiltinOffsetOf(const Stmt *S) { +bool containsBuiltinOffsetOf(const Stmt *S) { if (isa<OffsetOfExpr>(S)) return true; @@ -74,7 +78,7 @@ bool clang::ento::containsBuiltinOffsetOf(const Stmt *S) { // Extract lhs and rhs from assignment statement std::pair<const clang::VarDecl *, const clang::Expr *> -clang::ento::parseAssignment(const Stmt *S) { +parseAssignment(const Stmt *S) { const VarDecl *VD = nullptr; const Expr *RHS = nullptr; @@ -94,3 +98,18 @@ clang::ento::parseAssignment(const Stmt *S) { return std::make_pair(VD, RHS); } + +Nullability getNullabilityAnnotation(QualType Type) { + const auto *AttrType = Type->getAs<AttributedType>(); + if (!AttrType) + return Nullability::Unspecified; + if (AttrType->getAttrKind() == AttributedType::attr_nullable) + return Nullability::Nullable; + else if (AttrType->getAttrKind() == AttributedType::attr_nonnull) + return Nullability::Nonnull; + return Nullability::Unspecified; +} + + +} // end namespace ento +} // end namespace clang |