File indexing completed on 2026-05-10 08:37:07
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #ifndef LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_CHECKERHELPERS_H
0014 #define LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_CHECKERHELPERS_H
0015
0016 #include "ProgramState_Fwd.h"
0017 #include "SVals.h"
0018 #include "clang/AST/OperationKinds.h"
0019 #include "clang/AST/Stmt.h"
0020 #include "clang/Basic/OperatorKinds.h"
0021 #include <optional>
0022 #include <tuple>
0023
0024 namespace clang {
0025
0026 class Expr;
0027 class VarDecl;
0028 class QualType;
0029 class Preprocessor;
0030
0031 namespace ento {
0032
0033 bool containsMacro(const Stmt *S);
0034 bool containsEnum(const Stmt *S);
0035 bool containsStaticLocal(const Stmt *S);
0036 bool containsBuiltinOffsetOf(const Stmt *S);
0037 template <class T> bool containsStmt(const Stmt *S) {
0038 if (isa<T>(S))
0039 return true;
0040
0041 for (const Stmt *Child : S->children())
0042 if (Child && containsStmt<T>(Child))
0043 return true;
0044
0045 return false;
0046 }
0047
0048 std::pair<const clang::VarDecl *, const clang::Expr *>
0049 parseAssignment(const Stmt *S);
0050
0051
0052
0053
0054
0055
0056
0057 enum class Nullability : char {
0058 Contradicted,
0059
0060
0061
0062 Nullable,
0063 Unspecified,
0064 Nonnull
0065 };
0066
0067
0068 Nullability getNullabilityAnnotation(QualType Type);
0069
0070
0071
0072
0073
0074 std::optional<int> tryExpandAsInteger(StringRef Macro, const Preprocessor &PP);
0075
0076 class OperatorKind {
0077 union {
0078 BinaryOperatorKind Bin;
0079 UnaryOperatorKind Un;
0080 } Op;
0081 bool IsBinary;
0082
0083 public:
0084 explicit OperatorKind(BinaryOperatorKind Bin) : Op{Bin}, IsBinary{true} {}
0085 explicit OperatorKind(UnaryOperatorKind Un) : IsBinary{false} { Op.Un = Un; }
0086 bool IsBinaryOp() const { return IsBinary; }
0087
0088 BinaryOperatorKind GetBinaryOpUnsafe() const {
0089 assert(IsBinary && "cannot get binary operator - we have a unary operator");
0090 return Op.Bin;
0091 }
0092
0093 std::optional<BinaryOperatorKind> GetBinaryOp() const {
0094 if (IsBinary)
0095 return Op.Bin;
0096 return {};
0097 }
0098
0099 UnaryOperatorKind GetUnaryOpUnsafe() const {
0100 assert(!IsBinary &&
0101 "cannot get unary operator - we have a binary operator");
0102 return Op.Un;
0103 }
0104
0105 std::optional<UnaryOperatorKind> GetUnaryOp() const {
0106 if (!IsBinary)
0107 return Op.Un;
0108 return {};
0109 }
0110 };
0111
0112 OperatorKind operationKindFromOverloadedOperator(OverloadedOperatorKind OOK,
0113 bool IsBinary);
0114
0115 std::optional<SVal> getPointeeVal(SVal PtrSVal, ProgramStateRef State);
0116
0117
0118
0119 bool isWithinStdNamespace(const Decl *D);
0120
0121 }
0122
0123 }
0124
0125 #endif