clang  10.0.0svn
CheckerHelpers.h
Go to the documentation of this file.
1 //== CheckerHelpers.h - Helper functions for checkers ------------*- C++ -*--=//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file defines CheckerVisitor.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_CHECKERHELPERS_H
14 #define LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_CHECKERHELPERS_H
15 
16 #include "clang/AST/Stmt.h"
17 #include <tuple>
18 
19 namespace clang {
20 
21 class Expr;
22 class VarDecl;
23 class QualType;
24 class AttributedType;
25 
26 namespace ento {
27 
28 bool containsMacro(const Stmt *S);
29 bool containsEnum(const Stmt *S);
30 bool containsStaticLocal(const Stmt *S);
31 bool containsBuiltinOffsetOf(const Stmt *S);
32 template <class T> bool containsStmt(const Stmt *S) {
33  if (isa<T>(S))
34  return true;
35 
36  for (const Stmt *Child : S->children())
37  if (Child && containsStmt<T>(Child))
38  return true;
39 
40  return false;
41 }
42 
43 std::pair<const clang::VarDecl *, const clang::Expr *>
44 parseAssignment(const Stmt *S);
45 
46 // Do not reorder! The getMostNullable method relies on the order.
47 // Optimization: Most pointers expected to be unspecified. When a symbol has an
48 // unspecified or nonnull type non of the rules would indicate any problem for
49 // that symbol. For this reason only nullable and contradicted nullability are
50 // stored for a symbol. When a symbol is already contradicted, it can not be
51 // casted back to nullable.
52 enum class Nullability : char {
53  Contradicted, // Tracked nullability is contradicted by an explicit cast. Do
54  // not report any nullability related issue for this symbol.
55  // This nullability is propagated aggressively to avoid false
56  // positive results. See the comment on getMostNullable method.
57  Nullable,
59  Nonnull
60 };
61 
62 /// Get nullability annotation for a given type.
64 
65 } // end GR namespace
66 
67 } // end clang namespace
68 
69 #endif
A (possibly-)qualified type.
Definition: Type.h:643
bool containsStaticLocal(const Stmt *S)
Stmt - This represents one statement.
Definition: Stmt.h:66
The base class of the type hierarchy.
Definition: Type.h:1436
bool containsBuiltinOffsetOf(const Stmt *S)
child_range children()
Definition: Stmt.cpp:223
The l-value was considered opaque, so the alignment was determined from a type, but that type was an ...
bool containsStmt(const Stmt *S)
std::pair< const clang::VarDecl *, const clang::Expr * > parseAssignment(const Stmt *S)
Dataflow Directional Tag Classes.
Nullability getNullabilityAnnotation(QualType Type)
Get nullability annotation for a given type.
bool containsMacro(const Stmt *S)
bool containsEnum(const Stmt *S)