23 using namespace clang;
27 class DynamicTypePropagation:
30 check::PostStmt<ImplicitCastExpr>,
31 check::PostStmt<CXXNewExpr> > {
55 State = State->setDynamicTypeInfo(Region, Ty,
false);
60 void DynamicTypePropagation::checkPreCall(
const CallEvent &Call,
71 switch (Ctor->getOriginExpr()->getConstructionKind()) {
78 if (
const MemRegion *Target = Ctor->getCXXThisVal().getAsRegion())
88 if (!Dtor->isBaseDestructor())
91 const MemRegion *Target = Dtor->getCXXThisVal().getAsRegion();
95 const Decl *D = Dtor->getDecl();
104 void DynamicTypePropagation::checkPostCall(
const CallEvent &Call,
107 if (
const ObjCMethodCall *Msg = dyn_cast<ObjCMethodCall>(&Call)) {
118 switch (Msg->getMethodFamily()) {
129 const ObjCObjectType *ObjTy = getObjectTypeForAllocAndNew(MsgE, C);
134 C.
addTransition(State->setDynamicTypeInfo(RetReg, DynResTy,
false));
140 const MemRegion *RecReg = Msg->getReceiverSVal().getAsRegion();
144 C.
addTransition(State->setDynamicTypeInfo(RetReg, RecDynType));
154 switch (Ctor->getOriginExpr()->getConstructionKind()) {
165 if (
const MemRegion *Target = Ctor->getCXXThisVal().getAsRegion()) {
188 if (
const Type *NewTy = getBetterObjCType(CastE, C))
195 void DynamicTypePropagation::checkPostStmt(
const CXXNewExpr *NewE,
210 DynamicTypePropagation::getObjectTypeForAllocAndNew(
const ObjCMessageExpr *MsgE,
229 if (
const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(RecE)) {
236 dyn_cast<ObjCObjectType>(MD->getClassInterface()->getTypeForDecl()))
247 DynamicTypePropagation::getBetterObjCType(
const Expr *CastE,
CastKind getCastKind() const
MemRegion - The root abstract class for all memory regions.
QualType getClassReceiver() const
Returns the type of a class message send, or NULL if the message is not a class message.
ExplodedNode * addTransition(ProgramStateRef State=nullptr, const ProgramPointTag *Tag=nullptr)
Generates a new transition in the program state graph (ExplodedGraph). Uses the default CheckerContex...
QualType getRecordType(const RecordDecl *Decl) const
static void recordFixedType(const MemRegion *Region, const CXXMethodDecl *MD, CheckerContext &C)
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Represents any expression that calls an Objective-C method.
QualType getSuperType() const
Retrieve the type referred to by 'super'.
const CXXRecordDecl * getParent() const
Represents an ObjC class declaration.
const ProgramStateRef & getState() const
Stores the currently inferred strictest bound on the runtime type of a region in a given state along ...
Represents an implicit call to a C++ destructor.
bool hasRelatedResultType() const
Determine whether this method has a result type that is related to the message receiver's type...
An expression that sends a message to the given Objective-C object or class.
CHECKER * registerChecker()
Used to register checkers.
Represents a new-expression for memory allocation and constructor calls, e.g: "new CXXNewExpr(foo)"...
Represents a static or instance method of a struct/union/class.
const Decl * getDecl() const
const StackFrameContext * getStackFrame() const
Expr * getInstanceReceiver()
Returns the object expression (receiver) for an instance message, or null for a message that is not a...
bool isSuperClassOf(const ObjCInterfaceDecl *I) const
ASTContext & getASTContext()
QualType getPointerType(QualType T) const
Return the uniqued reference to the type for a pointer to the specified type.
QualType getObjCObjectPointerType(QualType OIT) const
Return a ObjCObjectPointerType type for the given ObjCObjectType.
const MemRegion * getAsRegion() const
Represents an abstract call to a function or method along a particular path.
Expr * IgnoreParenImpCasts() LLVM_READONLY
ObjCInterfaceDecl * getInterfaceDecl() const
const ImplicitParamDecl * getSelfDecl() const
A reference to a declared variable, function, enum, etc. [C99 6.5.1p2].
bool isNull() const
isNull - Return true if this QualType doesn't point to a type yet.
The receiver is a superclass.
SVal getReturnValue() const
Returns the return value of the call.
bool isObjCIdType() const
Represents a call to a C++ constructor.
ReceiverKind getReceiverKind() const
Determine the kind of receiver that this message is being sent to.
Defines enum values for all the target-independent builtin functions.
const LocationContext * getLocationContext() const
SVal getSVal(const Stmt *S) const
Get the value of arbitrary expressions at this point in the path.