16 #ifndef LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_CALLEVENT_H 17 #define LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_CALLEVENT_H 36 #include "llvm/ADT/ArrayRef.h" 37 #include "llvm/ADT/IntrusiveRefCntPtr.h" 38 #include "llvm/ADT/PointerIntPair.h" 39 #include "llvm/ADT/PointerUnion.h" 40 #include "llvm/ADT/STLExtras.h" 41 #include "llvm/ADT/SmallVector.h" 42 #include "llvm/ADT/StringRef.h" 43 #include "llvm/Support/Allocator.h" 44 #include "llvm/Support/Casting.h" 45 #include "llvm/Support/ErrorHandling.h" 52 class LocationContext;
54 class ProgramPointTag;
55 class StackFrameContext;
82 mutable bool IsLookupDone =
false;
85 std::vector<const char *> QualifiedName;
86 unsigned RequiredArgs;
102 unsigned RequiredArgs = NoArgRequirement)
103 : QualifiedName(QualifiedName), RequiredArgs(RequiredArgs) {}
109 template<
typename T = CallEvent>
116 return this->
get()->
template cloneWithState<T>(State);
121 template <
typename SuperT>
137 const Decl *D =
nullptr;
178 llvm::PointerUnion<const Expr *, const Decl *> Origin;
192 mutable unsigned RefCount = 0;
194 void Retain()
const { ++RefCount; }
195 void Release()
const;
201 : State(
std::move(state)), LCtx(lctx), Origin(E) {}
204 : State(
std::move(state)), LCtx(lctx), Origin(D) {}
208 : State(Original.State), LCtx(Original.LCtx), Origin(Original.Origin),
209 Data(Original.Data), Location(Original.Location) {}
212 virtual void cloneTo(
void *Dest)
const = 0;
216 return getState()->getSVal(S, getLocationContext());
236 return Origin.dyn_cast<
const Decl *>();
256 return Origin.dyn_cast<
const Expr *>();
264 virtual unsigned getNumArgs()
const = 0;
268 const Decl *D = getDecl();
275 getState()->getStateManager().getContext().getSourceManager();
281 if (
const auto *FD = dyn_cast<FunctionDecl>(D))
282 return FD->isOverloadedOperator() && FD->isImplicit() && FD->isGlobal();
297 return getOriginExpr()->getSourceRange();
301 virtual SVal getArgSVal(
unsigned Index)
const;
310 virtual SourceRange getArgSourceRange(
unsigned Index)
const;
319 SVal getReturnValue()
const;
323 bool hasNonNullArgumentsWithType(
bool (*Condition)(
QualType))
const;
326 bool hasNonZeroCallbackArg()
const;
329 bool hasVoidPointerToNonConstArg()
const;
337 return hasNonZeroCallbackArg();
356 bool isGlobalCFunction(StringRef SpecificName = StringRef())
const;
366 const auto *ND = dyn_cast_or_null<NamedDecl>(getDecl());
369 return ND->getIdentifier();
392 template <
typename T>
397 return cloneWithState<CallEvent>(NewState);
402 static bool isCallStmt(
const Stmt *S);
412 static bool isVariadic(
const Decl *D);
426 const VarRegion *getParameterLocation(
unsigned Index)
const;
437 getState(), {getOriginExpr(), Index}, getLocationContext()).hasValue();
446 return ASTArgumentIndex;
453 return CallArgumentIndex;
471 llvm::mapped_iterator<ArrayRef<ParmVarDecl *>::iterator, GetTypeFn>;
479 return llvm::map_iterator(parameters().begin(), GetTypeFn());
483 return llvm::map_iterator(parameters().end(), GetTypeFn());
487 void dump(raw_ostream &Out)
const;
512 bool argumentsMayEscape()
const override;
548 unsigned getNumArgs()
const override {
return getOriginExpr()->getNumArgs(); }
551 return getOriginExpr()->getArg(Index);
575 void getExtraInvalidatedValues(
ValueList &Values,
576 RegionAndSymbolInvalidationTraits *ETraits)
const override;
583 unsigned getNumArgs()
const override {
return getOriginExpr()->getNumArgs(); }
586 return getOriginExpr()->getArg(Index);
592 const BlockDataRegion *getBlockRegion()
const;
595 const BlockDataRegion *BR = getBlockRegion();
598 return BR->getDecl();
612 assert(isConversionFromLambda());
613 const BlockDataRegion *BR = getBlockRegion();
614 assert(BR &&
"Block converted from lambda must have a block region");
616 auto I = BR->referenced_vars_begin();
617 assert(I != BR->referenced_vars_end());
619 return I.getCapturedRegion();
623 if (!isConversionFromLambda())
624 return RuntimeDefinition(getDecl());
645 const VarDecl *LambdaVD = getRegionStoringCapturedLambda()->getDecl();
649 return RuntimeDefinition(LambdaCallOperator);
657 BindingsTy &Bindings)
const override;
680 void getExtraInvalidatedValues(
ValueList &Values,
681 RegionAndSymbolInvalidationTraits *ETraits)
const override;
688 virtual SVal getCXXThisVal()
const;
692 RuntimeDefinition getRuntimeDefinition()
const override;
695 BindingsTy &Bindings)
const override;
719 return cast<CXXMemberCallExpr>(CXXInstanceCall::getOriginExpr());
723 if (
const CallExpr *CE = getOriginExpr())
724 return CE->getNumArgs();
729 return getOriginExpr()->getArg(Index);
732 const Expr *getCXXThisExpr()
const override;
734 RuntimeDefinition getRuntimeDefinition()
const override;
762 return cast<CXXOperatorCallExpr>(CXXInstanceCall::getOriginExpr());
766 return getOriginExpr()->getNumArgs() - 1;
770 return getOriginExpr()->getArg(Index + 1);
773 const Expr *getCXXThisExpr()
const override;
792 return CallArgumentIndex + 1;
804 using DtorDataTy = llvm::PointerIntPair<const MemRegion *, 1, bool>;
814 const MemRegion *Target,
bool IsBaseDestructor,
817 Data =
DtorDataTy(Target, IsBaseDestructor).getOpaqueValue();
829 RuntimeDefinition getRuntimeDefinition()
const override;
832 SVal getCXXThisVal()
const override;
836 return DtorDataTy::getFromOpaqueValue(Data).getInt();
870 void getExtraInvalidatedValues(
ValueList &Values,
871 RegionAndSymbolInvalidationTraits *ETraits)
const override;
879 return getOriginExpr()->getConstructor();
882 unsigned getNumArgs()
const override {
return getOriginExpr()->getNumArgs(); }
885 return getOriginExpr()->getArg(Index);
889 SVal getCXXThisVal()
const;
892 BindingsTy &Bindings)
const override;
921 return getOriginExpr()->getOperatorNew();
928 return getOriginExpr()->passAlignment() ? 2 : 1;
932 return getOriginExpr()->getNumPlacementArgs() + getNumImplicitArgs();
937 if (Index < getNumImplicitArgs())
939 return getOriginExpr()->getPlacementArg(Index - getNumImplicitArgs());
947 return getOriginExpr()->getPlacementArg(Index);
986 void getExtraInvalidatedValues(
ValueList &Values,
987 RegionAndSymbolInvalidationTraits *ETraits)
const override;
999 return getOriginExpr()->getMethodDecl();
1003 return getOriginExpr()->getNumArgs();
1007 return getOriginExpr()->getArg(Index);
1011 return getOriginExpr()->isInstanceMessage();
1015 return getOriginExpr()->getMethodFamily();
1019 return getOriginExpr()->getSelector();
1025 SVal getReceiverSVal()
const;
1028 SVal getSelfSVal()
const;
1035 return getOriginExpr()->getReceiverInterface();
1039 bool isReceiverSelfOrSuper()
const;
1048 switch (getMessageKind()) {
1050 llvm_unreachable(
"This is not a pseudo-object access!");
1052 return getNumArgs() > 0;
1054 return getNumArgs() > 1;
1056 llvm_unreachable(
"Unknown message kind");
1064 RuntimeDefinition getRuntimeDefinition()
const override;
1066 bool argumentsMayEscape()
const override;
1069 BindingsTy &Bindings)
const override;
1090 llvm::BumpPtrAllocator &Alloc;
1093 using CallEventTemplateTy = SimpleFunctionCall;
1095 void reclaim(
const void *Memory) {
1096 Cache.push_back(const_cast<void *>(Memory));
1102 return Alloc.Allocate<CallEventTemplateTy>();
1104 return Cache.pop_back_val();
1107 template <
typename T,
typename Arg>
1109 static_assert(
sizeof(T) ==
sizeof(CallEventTemplateTy),
1110 "CallEvent subclasses are not all the same size");
1111 return new (allocate()) T(A, St, LCtx);
1114 template <
typename T,
typename Arg1,
typename Arg2>
1116 static_assert(
sizeof(T) ==
sizeof(CallEventTemplateTy),
1117 "CallEvent subclasses are not all the same size");
1118 return new (allocate()) T(A1, A2, St, LCtx);
1121 template <
typename T,
typename Arg1,
typename Arg2,
typename Arg3>
1124 static_assert(
sizeof(T) ==
sizeof(CallEventTemplateTy),
1125 "CallEvent subclasses are not all the same size");
1126 return new (allocate()) T(A1, A2, A3, St, LCtx);
1129 template <
typename T,
typename Arg1,
typename Arg2,
typename Arg3,
1133 static_assert(
sizeof(T) ==
sizeof(CallEventTemplateTy),
1134 "CallEvent subclasses are not all the same size");
1135 return new (allocate()) T(A1, A2, A3, A4, St, LCtx);
1155 CallEventRef<ObjCMethodCall>
1158 return create<ObjCMethodCall>(E,
State, LCtx);
1161 CallEventRef<CXXConstructorCall>
1164 return create<CXXConstructorCall>(E, Target,
State, LCtx);
1167 CallEventRef<CXXDestructorCall>
1169 const MemRegion *Target,
bool IsBase,
1171 return create<CXXDestructorCall>(DD, Trigger, Target, IsBase,
State, LCtx);
1174 CallEventRef<CXXAllocatorCall>
1177 return create<CXXAllocatorCall>(E,
State, LCtx);
1181 template <
typename T>
1183 assert(isa<T>(*
this) &&
"Cloning to unrelated type");
1184 static_assert(
sizeof(T) ==
sizeof(
CallEvent),
1185 "Subclasses may not add fields");
1187 if (NewState ==
State)
1188 return cast<T>(
this);
1191 T *Copy =
static_cast<T *
>(Mgr.allocate());
1193 assert(Copy->getKind() == this->
getKind() &&
"Bad copy");
1195 Copy->State = NewState;
1199 inline void CallEvent::Release()
const {
1200 assert(RefCount > 0 &&
"Reference count is already zero.");
1219 template<
class T>
struct simplify_type<
clang::ento::CallEventRef<T>> {
1230 #endif // LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_CALLEVENT_H A call to an overloaded operator written using operator syntax.
CallEvent(const CallEvent &Original)
Kind getKind() const override
Represents a function declaration or definition.
RuntimeDefinition(const Decl *InD, const MemRegion *InR)
Smart pointer class that efficiently represents Objective-C method names.
A (possibly-)qualified type.
MemRegion - The root abstract class for all memory regions.
CallEventRef< T > cloneWithState(ProgramStateRef NewState) const
Returns a copy of this CallEvent, but using the given state.
const CXXConstructorDecl * getDecl() const override
DominatorTree GraphTraits specialization so the DominatorTree can be iterable by generic graph iterat...
CXXInstanceCall(const FunctionDecl *D, ProgramStateRef St, const LocationContext *LCtx)
static SimpleType getSimplifiedValue(clang::ento::CallEventRef< T > Val)
TypePropertyCache< Private > Cache
void cloneTo(void *Dest) const override
Stmt - This represents one statement.
Information about invalidation for a particular region/symbol.
SimpleFunctionCall(const CallExpr *CE, ProgramStateRef St, const LocationContext *LCtx)
AnyFunctionCall(const Decl *D, ProgramStateRef St, const LocationContext *LCtx)
static bool classof(const CallEvent *CA)
C Language Family Type Representation.
Defines the SourceManager interface.
void cloneTo(void *Dest) const override
Decl - This represents one declaration (or definition), e.g.
CXXMemberOperatorCall(const CXXOperatorCallExpr *CE, ProgramStateRef St, const LocationContext *LCtx)
Manages the lifetime of CallEvent objects.
IntrusiveRefCntPtr< const ProgramState > ProgramStateRef
static bool classof(const CallEvent *CA)
ObjCMethodCall(const ObjCMessageExpr *Msg, ProgramStateRef St, const LocationContext *LCtx)
CallEventRef< CXXDestructorCall > getCXXDestructorCall(const CXXDestructorDecl *DD, const Stmt *Trigger, const MemRegion *Target, bool IsBase, ProgramStateRef State, const LocationContext *LCtx)
Represents a call to a C++ constructor.
Represents a C++ constructor within a class.
bool isBaseDestructor() const
Returns true if this is a call to a base class destructor.
const Expr * getOriginExpr() const
Returns the expression whose value will be the result of this call.
llvm::PointerIntPair< const MemRegion *, 1, bool > DtorDataTy
Represents a variable declaration or definition.
static bool classof(const CallEvent *CA)
SVal getSVal(const Stmt *S) const
Get the value of arbitrary expressions at this point in the path.
static Optional< SVal > getObjectUnderConstruction(ProgramStateRef State, const ConstructionContextItem &Item, const LocationContext *LC)
By looking at a certain item that may be potentially part of an object's ConstructionContext, retrieve such object's location.
ObjCMethodDecl - Represents an instance or class method declaration.
static bool classof(const CallEvent *CA)
Represents a C++ overloaded operator call where the operator is implemented as a non-static member fu...
Represents a parameter to a function.
Defines the clang::Expr interface and subclasses for C++ expressions.
unsigned getNumArgs() const override
Returns the number of arguments (explicit and implicit).
One of these records is kept for each identifier that is lexed.
unsigned getNumArgs() const override
param_type_iterator param_type_end() const
ObjCMethodFamily
A family of Objective-C methods.
virtual const CallExpr * getOriginExpr() const
AnalysisDeclContext contains the context data for the function or method under analysis.
const BlockDecl * getDecl() const override
const ObjCInterfaceDecl * getReceiverInterface() const
Get the interface for the receiver.
virtual const Expr * getArgExpr(unsigned Index) const
Returns the expression associated with a given argument.
i32 captured_struct **param SharedsTy A type which contains references the shared variables *param Shareds Context with the list of shared variables from the p *TaskFunction *param Data Additional data for task generation like final * state
bool argumentsMayEscape() const override
static bool classof(const CallEvent *CA)
Represents the memory allocation call in a C++ new-expression.
Kind getKind() const override
CallDescription(ArrayRef< const char *> QualifiedName, unsigned RequiredArgs=NoArgRequirement)
Constructs a CallDescription object.
virtual const CXXOperatorCallExpr * getOriginExpr() const
Represents any expression that calls an Objective-C method.
static bool classof(const CallEvent *CA)
virtual Kind getKind() const =0
Returns the kind of call this is.
const FunctionDecl * getDecl() const override
static void dump(llvm::raw_ostream &OS, StringRef FunctionName, ArrayRef< CounterExpression > Expressions, ArrayRef< CounterMappingRegion > Regions)
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified...
bool isSetter() const
Returns true if this property access or subscript is a setter (has the form of an assignment)...
virtual const CXXConstructExpr * getOriginExpr() const
const FunctionDecl * getDecl() const override
Returns the declaration of the function or method that will be called.
param_type_iterator param_type_begin() const
Returns an iterator over the types of the call's formal parameters.
std::pair< Loc, SVal > FrameBindingTy
Represents an ObjC class declaration.
BlockCall(const CallExpr *CE, ProgramStateRef St, const LocationContext *LCtx)
Represents a non-static C++ member function call.
RuntimeDefinition getRuntimeDefinition() const override
ObjCMessageKind
Represents the ways an Objective-C message send can occur.
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
const Expr * getPlacementArgExpr(unsigned Index) const
Number of placement arguments to the operator new() call.
Represents a non-static C++ member function call, no matter how it is written.
const LocationContext * getLocationContext() const
The context in which the call is being evaluated.
CallEventManager(llvm::BumpPtrAllocator &alloc)
Pepresents a block literal declaration, which is like an unnamed FunctionDecl.
This represents one expression.
const Expr * getArgExpr(unsigned Index) const override
unsigned getNumArgs() const override
bool isInSystemHeader(SourceLocation Loc) const
Returns if a SourceLocation is in a system header.
unsigned getNumArgs() const override
Represents an implicit call to a C++ destructor.
Kind getKind() const override
Represents a C++ destructor within a class.
llvm::mapped_iterator< ArrayRef< ParmVarDecl * >::iterator, GetTypeFn > param_type_iterator
virtual const CXXNewExpr * getOriginExpr() const
Represents a call to any sort of function that might have a FunctionDecl.
bool isInSystemHeader() const
Returns true if the callee is known to be from a system header.
Optional< unsigned > getAdjustedParameterIndex(unsigned ASTArgumentIndex) const override
const IdentifierInfo * getCalleeIdentifier() const
Returns the name of the callee, if its name is a simple identifier.
Kind getKind() const override
Returns the kind of call this is.
virtual const CallExpr * getOriginExpr() const
StringRef getFunctionName() const
Get the name of the function that this object matches.
Defines the clang::IdentifierInfo, clang::IdentifierTable, and clang::Selector interfaces.
virtual const Decl * getDecl() const
Returns the declaration of the function or method that will be called.
Kind getKind() const override
CallEvent(const Decl *D, ProgramStateRef state, const LocationContext *lctx)
An expression that sends a message to the given Objective-C object or class.
virtual const Expr * getCXXThisExpr() const
Returns the expression representing the implicit 'this' object.
CallEventRef< ObjCMethodCall > getObjCMethodCall(const ObjCMessageExpr *E, ProgramStateRef State, const LocationContext *LCtx)
Represents a C function or static C++ member function call.
const VarRegion * getRegionStoringCapturedLambda() const
For a block converted from a C++ lambda, returns the block VarRegion for the variable holding the cap...
unsigned getNumArgs() const override
virtual bool argumentsMayEscape() const
Returns true if any of the arguments are known to escape to long- term storage, even if this method w...
SourceLocation getEndLoc() const LLVM_READONLY
static bool classof(const CallEvent *CA)
const Expr * getArgExpr(unsigned Index) const override
virtual SourceRange getSourceRange() const
Returns a source range for the entire call, suitable for outputting in diagnostics.
void cloneTo(void *Dest) const override
Defines the runtime definition of the called function.
Kind getKind() const override
CXXMemberCall(const CXXMemberCallExpr *CE, ProgramStateRef St, const LocationContext *LCtx)
PseudoObjectExpr - An expression which accesses a pseudo-object l-value.
This class represents a description of a function call using the number of arguments and the name of ...
CallEventRef< CXXAllocatorCall > getCXXAllocatorCall(const CXXNewExpr *E, ProgramStateRef State, const LocationContext *LCtx)
Encodes a location in the source.
const Expr * getArgExpr(unsigned Index) const override
CallEventRef(const T *Call)
ProgramPoints can be "tagged" as representing points specific to a given analysis entity...
Represents a new-expression for memory allocation and constructor calls, e.g: "new CXXNewExpr(foo)"...
CXXAllocatorCall(const CXXNewExpr *E, ProgramStateRef St, const LocationContext *LCtx)
bool isArgumentConstructedDirectly(unsigned Index) const
Returns true if on the current path, the argument was constructed by calling a C++ constructor over i...
Represents a call to a member function that may be written either with member call syntax (e...
Represents a static or instance method of a struct/union/class.
const Expr * getArgExpr(unsigned Index) const override
Returns the expression associated with a given argument.
bool isConversionFromLambda() const
SVal - This represents a symbolic expression, which can be either an L-value or an R-value...
unsigned getNumImplicitArgs() const
Number of non-placement arguments to the call.
virtual Optional< unsigned > getAdjustedParameterIndex(unsigned ASTArgumentIndex) const
Some calls have parameter numbering mismatched from argument numbering.
Represents one property declaration in an Objective-C interface.
unsigned getNumArgs() const override
void cloneTo(void *Dest) const override
void cloneTo(void *Dest) const override
const Expr * getArgExpr(unsigned Index) const override
virtual void getExtraInvalidatedValues(ValueList &Values, RegionAndSymbolInvalidationTraits *ETraits) const
Used to specify non-argument regions that will be invalidated as a result of this call...
const MemRegion * getDispatchRegion()
When other definitions are possible, returns the region whose runtime type determines the method defi...
const ObjCMethodDecl * getDecl() const override
CXXConstructorCall(const CXXConstructExpr *CE, const MemRegion *Target, ProgramStateRef St, const LocationContext *LCtx)
Creates a constructor call.
void cloneTo(void *Dest) const override
virtual const ObjCMessageExpr * getOriginExpr() const
static const unsigned NoArgRequirement
Selector getSelector() const
Dataflow Directional Tag Classes.
bool isValid() const
Return true if this is a valid SourceLocation object.
CXXMethodDecl * getLambdaCallOperator() const
Retrieve the lambda call operator of the closure type if this is a closure type.
static bool classof(const CallEvent *CA)
bool isConversionFromLambda() const
static bool classof(const CallEvent *CA)
virtual const CXXMemberCallExpr * getOriginExpr() const
std::unique_ptr< DiagnosticConsumer > create(StringRef OutputFile, DiagnosticOptions *Diags, bool MergeChildRecords=false)
Returns a DiagnosticConsumer that serializes diagnostics to a bitcode file.
Kind getKind() const override
RuntimeDefinition(const Decl *InD)
bool mayHaveOtherDefinitions()
Check if the definition we have is precise.
Represents an abstract call to a function or method along a particular path.
SourceRange getSourceRange() const override
bool isInstanceMessage() const
CXXInstanceCall(const CallExpr *CE, ProgramStateRef St, const LocationContext *LCtx)
CallEventRef cloneWithState(ProgramStateRef NewState) const
Returns a copy of this CallEvent, but using the given state.
virtual unsigned getASTArgumentIndex(unsigned CallArgumentIndex) const
Some call event sub-classes conveniently adjust mismatching AST indices to match parameter indices...
ObjCMethodFamily getMethodFamily() const
const Expr * getArgExpr(unsigned Index) const override
unsigned getNumArgs() const override
unsigned getASTArgumentIndex(unsigned CallArgumentIndex) const override
void cloneTo(void *Dest) const override
static bool classof(const CallEvent *CE)
CallEventRef< CXXConstructorCall > getCXXConstructorCall(const CXXConstructExpr *E, const MemRegion *Target, ProgramStateRef State, const LocationContext *LCtx)
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate.h) and friends (in DeclFriend.h).
const ProgramStateRef & getState() const
The state in which the call is being evaluated.
const Expr * getArgExpr(unsigned Index) const override
Defines the clang::SourceLocation class and associated facilities.
Represents a C++ struct/union/class.
unsigned getNumArgs() const override
CallEvent(const Expr *E, ProgramStateRef state, const LocationContext *lctx)
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
__DEVICE__ int max(int __a, int __b)
static Decl::Kind getKind(const Decl *D)
AnyFunctionCall(const Expr *E, ProgramStateRef St, const LocationContext *LCtx)
A trivial tuple used to represent a source range.
CXXDestructorCall(const CXXDestructorDecl *DD, const Stmt *Trigger, const MemRegion *Target, bool IsBaseDestructor, ProgramStateRef St, const LocationContext *LCtx)
Creates an implicit destructor.
Represents a call to a C++ constructor.
This class handles loading and caching of source files into memory.
void cloneTo(void *Dest) const override
Copies this CallEvent, with vtable intact, into a new block of memory.
SourceLocation getLocation() const
CallEventRef(const CallEventRef &Orig)
Kind getKind() const override
CallEventRef< T > cloneWithState(ProgramStateRef State) const
ArrayRef< SVal > ValueList