20#include "llvm/ADT/STLExtras.h"
30 return llvm::any_of(S->
children(), [Pred](
const Stmt *Child) {
31 return Child && Pred(Child);
62 if (VD->isStaticLocal())
77std::pair<const clang::VarDecl *, const clang::Expr *>
80 const Expr *RHS =
nullptr;
82 if (
auto Assign = dyn_cast_or_null<BinaryOperator>(S)) {
83 if (Assign->isAssignmentOp()) {
85 RHS = Assign->getRHS();
86 if (
auto DE = dyn_cast_or_null<DeclRefExpr>(Assign->getLHS()))
87 VD = dyn_cast_or_null<VarDecl>(DE->getDecl());
89 }
else if (
auto PD = dyn_cast_or_null<DeclStmt>(S)) {
91 assert(PD->isSingleDecl() &&
"We process decls one by one");
96 return std::make_pair(VD, RHS);
100 const auto *AttrType =
Type->
getAs<AttributedType>();
103 if (AttrType->getAttrKind() == attr::TypeNullable)
105 else if (AttrType->getAttrKind() == attr::TypeNonNull)
119 std::vector<Token> FilteredTokens;
120 FilteredTokens.reserve(MI->
tokens().size());
121 auto IsNotParen = [](
const Token &T) {
122 return !T.isOneOf(tok::l_paren, tok::r_paren);
124 llvm::copy_if(MI->
tokens(), std::back_inserter(FilteredTokens), IsNotParen);
126 if (FilteredTokens.empty())
130 const Token &T = FilteredTokens.back();
135 bool InvalidSpelling =
false;
139 StringRef ValueStr = PP.
getSpelling(T, Buffer, &InvalidSpelling);
144 llvm::APSInt IntValue(0,
true);
145 constexpr unsigned AutoSenseRadix = 0;
146 if (ValueStr.getAsInteger(AutoSenseRadix,
147 static_cast<llvm::APInt &
>(IntValue)))
151 size_t Size = FilteredTokens.size();
153 if (FilteredTokens[Size - 2].
is(tok::minus)) {
155 if (IntValue.isSignBitSet())
156 IntValue = IntValue.extend(IntValue.getBitWidth() + 1);
157 IntValue.setIsUnsigned(
false);
158 IntValue = -IntValue;
166 if (IntType.testInRange(IntValue,
true) !=
169 return IntType.convert(IntValue).getExtValue();
174 llvm::StringMap<BinaryOperatorKind> BinOps{
175#define BINARY_OPERATION(Name, Spelling) {Spelling, BO_##Name},
176#include "clang/AST/OperationKinds.def"
178 llvm::StringMap<UnaryOperatorKind> UnOps{
179#define UNARY_OPERATION(Name, Spelling) {Spelling, UO_##Name},
180#include "clang/AST/OperationKinds.def"
184#define OVERLOADED_OPERATOR(Name, Spelling, Token, Unary, Binary, MemberOnly) \
187 auto BinOpIt = BinOps.find(Spelling); \
188 if (BinOpIt != BinOps.end()) \
189 return OperatorKind(BinOpIt->second); \
191 llvm_unreachable("operator was expected to be binary but is not"); \
193 auto UnOpIt = UnOps.find(Spelling); \
194 if (UnOpIt != UnOps.end()) \
195 return OperatorKind(UnOpIt->second); \
197 llvm_unreachable("operator was expected to be unary but is not"); \
200#include "clang/Basic/OperatorKinds.def"
202 llvm_unreachable(
"unexpected operator kind");
208 return State->getSVal(Ptr);
216 if (
const auto *NS = dyn_cast<NamespaceDecl>(DC);
217 NS && NS->isStdNamespace())
Defines the clang::Preprocessor interface.
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
DeclContext * getParent()
getParent - Returns the containing DeclContext.
A reference to a declared variable, function, enum, etc.
Decl - This represents one declaration (or definition), e.g.
DeclContext * getDeclContext()
This represents one expression.
Encapsulates the data about a macro definition (e.g.
ArrayRef< Token > tokens() const
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
const MacroInfo * getMacroInfo(const IdentifierInfo *II) const
IdentifierInfo * getIdentifierInfo(StringRef Name) const
Return information about the specified preprocessor identifier token.
const TargetInfo & getTargetInfo() const
StringRef getSpelling(SourceLocation loc, SmallVectorImpl< char > &buffer, bool *invalid=nullptr) const
Return the 'spelling' of the token at the given location; does not go up to the spelling location or ...
A (possibly-)qualified type.
Stmt - This represents one statement.
SourceLocation getEndLoc() const LLVM_READONLY
SourceLocation getBeginLoc() const LLVM_READONLY
unsigned getIntWidth() const
getIntWidth/Align - Return the size of 'signed int' and 'unsigned int' for this target,...
Token - This structure provides full information about a lexed token.
The base class of the type hierarchy.
const T * getAs() const
Member-template getAs<specific type>'.
Represents a variable declaration or definition.
const Expr * getAnyInitializer() const
Get the initializer for this variable, no matter which declaration it is attached to.
A record of the "type" of an APSInt, used for conversions.
@ RTR_Within
Value is representable using this type.
SVal - This represents a symbolic expression, which can be either an L-value or an R-value.
const MemRegion * getAsRegion() const
Defines the clang::TargetInfo interface.
bool containsEnum(const Stmt *S)
Nullability getNullabilityAnnotation(QualType Type)
Get nullability annotation for a given type.
bool isWithinStdNamespace(const Decl *D)
Returns true if declaration D is in std namespace or any nested namespace or class scope.
IntrusiveRefCntPtr< const ProgramState > ProgramStateRef
bool containsStaticLocal(const Stmt *S)
std::pair< const clang::VarDecl *, const clang::Expr * > parseAssignment(const Stmt *S)
OperatorKind operationKindFromOverloadedOperator(OverloadedOperatorKind OOK, bool IsBinary)
bool containsBuiltinOffsetOf(const Stmt *S)
std::optional< SVal > getPointeeVal(SVal PtrSVal, ProgramStateRef State)
static bool anyChild(const Stmt *S, bool(*Pred)(const Stmt *))
std::optional< int > tryExpandAsInteger(StringRef Macro, const Preprocessor &PP)
Try to parse the value of a defined preprocessor macro.
bool containsMacro(const Stmt *S)
Top level wrappers for InstallAPI frontend operations.
OverloadedOperatorKind
Enumeration specifying the different kinds of C++ overloaded operators.
bool isa(CodeGen::Address addr)
U cast(CodeGen::Address addr)