CheckerHelpers.h revision 341825
1//== CheckerHelpers.h - Helper functions for checkers ------------*- C++ -*--=//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10//  This file defines CheckerVisitor.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_CHECKERHELPERS_H
15#define LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_CHECKERHELPERS_H
16
17#include "clang/AST/Stmt.h"
18#include <tuple>
19
20namespace clang {
21
22class Expr;
23class VarDecl;
24class QualType;
25class AttributedType;
26
27namespace ento {
28
29bool containsMacro(const Stmt *S);
30bool containsEnum(const Stmt *S);
31bool containsStaticLocal(const Stmt *S);
32bool containsBuiltinOffsetOf(const Stmt *S);
33template <class T> bool containsStmt(const Stmt *S) {
34  if (isa<T>(S))
35      return true;
36
37  for (const Stmt *Child : S->children())
38    if (Child && containsStmt<T>(Child))
39      return true;
40
41  return false;
42}
43
44std::pair<const clang::VarDecl *, const clang::Expr *>
45parseAssignment(const Stmt *S);
46
47// Do not reorder! The getMostNullable method relies on the order.
48// Optimization: Most pointers expected to be unspecified. When a symbol has an
49// unspecified or nonnull type non of the rules would indicate any problem for
50// that symbol. For this reason only nullable and contradicted nullability are
51// stored for a symbol. When a symbol is already contradicted, it can not be
52// casted back to nullable.
53enum class Nullability : char {
54  Contradicted, // Tracked nullability is contradicted by an explicit cast. Do
55                // not report any nullability related issue for this symbol.
56                // This nullability is propagated aggressively to avoid false
57                // positive results. See the comment on getMostNullable method.
58  Nullable,
59  Unspecified,
60  Nonnull
61};
62
63/// Get nullability annotation for a given type.
64Nullability getNullabilityAnnotation(QualType Type);
65
66} // end GR namespace
67
68} // end clang namespace
69
70#endif
71