clang 10.0.0git

Functions
DynamicTypePropagation.cpp File Reference
`#include "clang/AST/ParentMap.h"`
`#include "clang/AST/RecursiveASTVisitor.h"`
`#include "clang/Basic/Builtins.h"`
`#include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h"`
`#include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"`
`#include "clang/StaticAnalyzer/Core/Checker.h"`
`#include "clang/StaticAnalyzer/Core/CheckerManager.h"`
`#include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h"`
`#include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"`
`#include "clang/StaticAnalyzer/Core/PathSensitive/DynamicType.h"`
`#include "clang/StaticAnalyzer/Core/PathSensitive/ProgramStateTrait.h"`
Include dependency graph for DynamicTypePropagation.cpp:

Go to the source code of this file.

## Functions
| REGISTER_MAP_WITH_PROGRAMSTATE (MostSpecializedTypeArgsMap, SymbolRef, const ObjCObjectPointerType *) namespace
static void | recordFixedType (const MemRegion *Region, const CXXMethodDecl *MD, CheckerContext &C)
static const ObjCObjectPointerType * | getMostInformativeDerivedClassImpl (const ObjCObjectPointerType *From, const ObjCObjectPointerType *To, const ObjCObjectPointerType *MostInformativeCandidate, ASTContext &C)
static const ObjCObjectPointerType * | getMostInformativeDerivedClass (const ObjCObjectPointerType *From, const ObjCObjectPointerType *To, ASTContext &C)
| A downcast may loose specialization information. More...
static bool | storeWhenMoreInformative (ProgramStateRef &State, SymbolRef Sym, const ObjCObjectPointerType *const *Current, const ObjCObjectPointerType *StaticLowerBound, const ObjCObjectPointerType *StaticUpperBound, ASTContext &C)
| Inputs: More...
static const Expr * | stripCastsAndSugar (const Expr *E)
static bool | isObjCTypeParamDependent (QualType Type)
static const ObjCMethodDecl * | findMethodDecl (const ObjCMessageExpr *MessageExpr, const ObjCObjectPointerType *TrackedType, ASTContext &ASTCtxt)
| A method might not be available in the interface indicated by the static type. More...
static QualType | getReturnTypeForMethod (const ObjCMethodDecl *Method, ArrayRef< QualType > TypeArgs, const ObjCObjectPointerType *SelfType, ASTContext &C)
| Get the returned ObjCObjectPointerType by a method based on the tracked type information, or null pointer when the returned type is not an ObjCObjectPointerType. More...

## Function Documentation

## ◆ findMethodDecl()

static const ObjCMethodDecl* findMethodDecl | ( | const ObjCMessageExpr * | MessageExpr,
|  | const ObjCObjectPointerType * | TrackedType,
|  | ASTContext & | ASTCtxt
| ) |  |
| static

A method might not be available in the interface indicated by the static type.

However it might be available in the tracked type. In order to properly substitute the type parameters we need the declaration context of the method. The more specialized the enclosing class of the method is, the more likely that the parameter substitution will be successful.

Definition at line 649 of file DynamicTypePropagation.cpp.

References clang::ASTContext::canAssignObjCInterfaces(), clang::ObjCMessageExpr::Class, clang::Type::getAs(), clang::ObjCObjectPointerType::getInterfaceDecl(), clang::ObjCMessageExpr::getMethodDecl(), clang::ObjCMessageExpr::getReceiverKind(), clang::ObjCMessageExpr::getReceiverType(), clang::ObjCMessageExpr::getSelector(), clang::ObjCMessageExpr::Instance, clang::Type::isObjCClassType(), clang::Type::isObjCIdType(), clang::ObjCInterfaceDecl::lookupClassMethod(), and clang::ObjCInterfaceDecl::lookupInstanceMethod().

Referenced by getReturnTypeForMethod().

## ◆ getMostInformativeDerivedClass()

static const ObjCObjectPointerType* getMostInformativeDerivedClass | ( | const ObjCObjectPointerType * | From,
|  | const ObjCObjectPointerType * | To,
|  | ASTContext & | C
| ) |  |
| static

A downcast may loose specialization information.

E. g.: MutableMap<T, U> : Map The downcast to MutableMap looses the information about the types of the Map (due to the type parameters are not being forwarded to Map), and in general there is no way to recover that information from the declaration. In order to have to most information, lets find the most derived type that has all the type parameters forwarded.

Get the a subclass of `From` (which has a lower bound `To`) that do not loose information about type parameters. `To` has to be a subclass of `From`. From has to be specialized.

Definition at line 422 of file DynamicTypePropagation.cpp.

References getMostInformativeDerivedClassImpl().

## ◆ getMostInformativeDerivedClassImpl()

static const ObjCObjectPointerType* getMostInformativeDerivedClassImpl | ( | const ObjCObjectPointerType * | From,
|  | const ObjCObjectPointerType * | To,
|  | const ObjCObjectPointerType * | MostInformativeCandidate,
|  | ASTContext & | C
| ) |  |
| static

Definition at line 376 of file DynamicTypePropagation.cpp.

References clang::Type::castAs(), clang::ObjCInterfaceDecl::getCanonicalDecl(), clang::ObjCObjectPointerType::getInterfaceDecl(), clang::ASTContext::getObjCObjectPointerType(), clang::ObjCObjectPointerType::getObjectType(), clang::ObjCObjectType::getSuperClassType(), clang::QualType::isNull(), clang::ObjCObjectPointerType::isSpecialized(), and clang::ObjCObjectPointerType::isUnspecialized().

Referenced by getMostInformativeDerivedClass().

## ◆ getReturnTypeForMethod()

static QualType getReturnTypeForMethod | ( | const ObjCMethodDecl * | Method,
|  | ArrayRef< QualType > | TypeArgs,
|  | const ObjCObjectPointerType * | SelfType,
|  | ASTContext & | C
| ) |  |
| static

Get the returned ObjCObjectPointerType by a method based on the tracked type information, or null pointer when the returned type is not an ObjCObjectPointerType.

Definition at line 683 of file DynamicTypePropagation.cpp.

References clang::ASTContext::canAssignObjCInterfaces(), clang::Type::castAs(), clang::ObjCMessageExpr::Class, findMethodDecl(), clang::ObjCMessageExpr::getArg(), clang::Type::getAs(), clang::Selector::getAsString(), clang::ObjCMethodDecl::getClassInterface(), clang::ObjCMessageExpr::getClassReceiver(), clang::Decl::getDeclContext(), clang::ASTContext::getObjCInstanceType(), clang::ObjCMethodCall::getOriginExpr(), clang::ento::getRawDynamicTypeInfo(), clang::ObjCMessageExpr::getReceiverKind(), clang::ObjCMethodCall::getReceiverSVal(), clang::ObjCMethodDecl::getReturnType(), clang::ObjCMessageExpr::getSelector(), clang::Stmt::getSourceRange(), clang::Expr::getType(), clang::ValueDecl::getType(), clang::ObjCInterfaceDecl::getTypeParamList(), clang::Invariant, clang::QualType::isNull(), isObjCTypeParamDependent(), clang::ento::OS, clang::ObjCMethodDecl::param_size(), clang::Parameter, clang::ObjCMethodDecl::parameters(), clang::QualType::print(), clang::Result, clang::ento::setDynamicTypeInfo(), clang::CodeGen::state, State, stripCastsAndSugar(), and clang::QualType::substObjCTypeArgs().

## ◆ isObjCTypeParamDependent()

static bool isObjCTypeParamDependent | ( | QualType | Type | ) |
| static

Definition at line 619 of file DynamicTypePropagation.cpp.

References clang::ObjCTypeParamType::getDecl().

Referenced by getReturnTypeForMethod().

## ◆ recordFixedType()

static void recordFixedType | ( | const MemRegion * | Region,
|  | const CXXMethodDecl * | MD,
|  | CheckerContext & | C
| ) |  |
| static

Definition at line 131 of file DynamicTypePropagation.cpp.

References clang::CXXConstructExpr::CK_Complete, clang::CXXConstructExpr::CK_Delegating, clang::CXXConstructExpr::CK_NonVirtualBase, clang::CXXConstructExpr::CK_VirtualBase, clang::ObjCMessageExpr::Class, clang::Type::getAs(), clang::ObjCMessageExpr::getClassReceiver(), clang::LocationContext::getDecl(), clang::ento::getDynamicTypeInfo(), clang::ObjCMessageExpr::getInstanceReceiver(), clang::ObjCObjectPointerType::getInterfaceDecl(), clang::ParentMap::getParent(), clang::CXXMethodDecl::getParent(), clang::LocationContext::getParentMap(), clang::ASTContext::getPointerType(), clang::ObjCMessageExpr::getReceiverKind(), clang::ASTContext::getRecordType(), clang::LocationContext::getSelfDecl(), clang::LocationContext::getStackFrame(), clang::ObjCMessageExpr::getSuperType(), clang::Expr::getType(), clang::ObjCMethodDecl::hasRelatedResultType(), clang::Expr::IgnoreParenImpCasts(), clang::CXXNewExpr::isArray(), clang::QualType::isNull(), clang::ObjCObjectPointerType::isObjCIdType(), clang::ObjCInterfaceDecl::isSuperClassOf(), clang::OMF_alloc, clang::OMF_init, clang::OMF_new, clang::ento::setDynamicTypeInfo(), State, clang::ObjCMessageExpr::SuperClass, and clang::Target.

## ◆ REGISTER_MAP_WITH_PROGRAMSTATE()

REGISTER_MAP_WITH_PROGRAMSTATE | ( | MostSpecializedTypeArgsMap | ,
|  | SymbolRef | ,
|  | const ObjCObjectPointerType * |
| ) |  |

Return a better dynamic type if one can be derived from the cast.

This value is set to true, when the Generics checker is turned on.

Definition at line 46 of file DynamicTypePropagation.cpp.

References clang::ento::categories::CoreFoundationObjectiveC, and State.

## ◆ storeWhenMoreInformative()

static bool storeWhenMoreInformative | ( | ProgramStateRef & | State,
|  | SymbolRef | Sym,
|  | const ObjCObjectPointerType *const * | Current,
|  | const ObjCObjectPointerType * | StaticLowerBound,
|  | const ObjCObjectPointerType * | StaticUpperBound,
|  | ASTContext & | C
| ) |  |
| static

Inputs:

Parameters

  StaticLowerBound | Static lower bound for a symbol. The dynamic lower bound might be the subclass of this type.
  StaticUpperBound | A static upper bound for a symbol. `StaticLowerBound` expected to be the subclass of `StaticUpperBound`.
  Current | The type that was inferred for a symbol in a previous context. Might be null when this is the first time that inference happens. Precondition: `StaticLowerBound` or `StaticUpperBound` is specialized. If `Current` is not null, it is specialized. Possible cases: (1) The `Current` is null and `StaticLowerBound` <: `StaticUpperBound` (2) `StaticLowerBound` <: `Current` <: `StaticUpperBound` (3) `Current` <: `StaticLowerBound` <: `StaticUpperBound` (4) `StaticLowerBound` <: `StaticUpperBound` <: `Current` Effect: Use getMostInformativeDerivedClass with the upper and lower bound of the set {`StaticLowerBound`, `Current`, `StaticUpperBound}`. The computed lower bound must be specialized. If the result differs from `Current` or `Current` is null, store the result.

Definition at line 448 of file DynamicTypePropagation.cpp.

## ◆ stripCastsAndSugar()

static const Expr* stripCastsAndSugar | ( | const Expr * | E | ) |
| static

Definition at line 610 of file DynamicTypePropagation.cpp.

References clang::Expr::IgnoreParenImpCasts().

Referenced by getReturnTypeForMethod().