diff options
Diffstat (limited to 'lib/StaticAnalyzer/Core/CheckerHelpers.cpp')
-rw-r--r-- | lib/StaticAnalyzer/Core/CheckerHelpers.cpp | 29 |
1 files changed, 24 insertions, 5 deletions
diff --git a/lib/StaticAnalyzer/Core/CheckerHelpers.cpp b/lib/StaticAnalyzer/Core/CheckerHelpers.cpp index ed41914ebd054..b9facffcc8b51 100644 --- a/lib/StaticAnalyzer/Core/CheckerHelpers.cpp +++ b/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 |