CheckerHelpers.h revision 360660
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 19namespace clang { 20 21class Expr; 22class VarDecl; 23class QualType; 24class AttributedType; 25 26namespace ento { 27 28bool containsMacro(const Stmt *S); 29bool containsEnum(const Stmt *S); 30bool containsStaticLocal(const Stmt *S); 31bool containsBuiltinOffsetOf(const Stmt *S); 32template <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 43std::pair<const clang::VarDecl *, const clang::Expr *> 44parseAssignment(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. 52enum 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, 58 Unspecified, 59 Nonnull 60}; 61 62/// Get nullability annotation for a given type. 63Nullability getNullabilityAnnotation(QualType Type); 64 65} // end GR namespace 66 67} // end clang namespace 68 69#endif 70