clang  12.0.0git
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 "llvm/ADT/Optional.h"
18 #include <tuple>
19 
20 namespace clang {
21 
22 class Expr;
23 class VarDecl;
24 class QualType;
25 class AttributedType;
26 class Preprocessor;
27 
28 namespace ento {
29 
30 bool containsMacro(const Stmt *S);
31 bool containsEnum(const Stmt *S);
32 bool containsStaticLocal(const Stmt *S);
33 bool containsBuiltinOffsetOf(const Stmt *S);
34 template <class T> bool containsStmt(const Stmt *S) {
35  if (isa<T>(S))
36  return true;
37 
38  for (const Stmt *Child : S->children())
39  if (Child && containsStmt<T>(Child))
40  return true;
41 
42  return false;
43 }
44 
45 std::pair<const clang::VarDecl *, const clang::Expr *>
46 parseAssignment(const Stmt *S);
47 
48 // Do not reorder! The getMostNullable method relies on the order.
49 // Optimization: Most pointers expected to be unspecified. When a symbol has an
50 // unspecified or nonnull type non of the rules would indicate any problem for
51 // that symbol. For this reason only nullable and contradicted nullability are
52 // stored for a symbol. When a symbol is already contradicted, it can not be
53 // casted back to nullable.
54 enum class Nullability : char {
55  Contradicted, // Tracked nullability is contradicted by an explicit cast. Do
56  // not report any nullability related issue for this symbol.
57  // This nullability is propagated aggressively to avoid false
58  // positive results. See the comment on getMostNullable method.
59  Nullable,
61  Nonnull
62 };
63 
64 /// Get nullability annotation for a given type.
66 
67 /// Try to parse the value of a defined preprocessor macro. We can only parse
68 /// simple expressions that consist of an optional minus sign token and then a
69 /// token for an integer. If we cannot parse the value then None is returned.
70 llvm::Optional<int> tryExpandAsInteger(StringRef Macro, const Preprocessor &PP);
71 
72 } // namespace ento
73 
74 } // namespace clang
75 
76 #endif
A (possibly-)qualified type.
Definition: Type.h:655
bool containsStaticLocal(const Stmt *S)
Stmt - This represents one statement.
Definition: Stmt.h:68
The base class of the type hierarchy.
Definition: Type.h:1472
bool containsBuiltinOffsetOf(const Stmt *S)
llvm::Optional< int > tryExpandAsInteger(StringRef Macro, const Preprocessor &PP)
Try to parse the value of a defined preprocessor macro.
child_range children()
Definition: Stmt.cpp:224
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)
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
Definition: Preprocessor.h:128