26 const Expr *
E,
bool StopAtFirstRefCountedObj,
31 if (
auto *DRE = dyn_cast<DeclRefExpr>(
E)) {
32 if (
auto *VD = dyn_cast_or_null<VarDecl>(DRE->getDecl())) {
33 auto QT = VD->getType();
34 if (VD->hasGlobalStorage() && QT.isConstQualified()) {
35 return callback(
E,
true);
39 if (
auto *tempExpr = dyn_cast<MaterializeTemporaryExpr>(
E)) {
40 E = tempExpr->getSubExpr();
43 if (
auto *tempExpr = dyn_cast<CXXBindTemporaryExpr>(
E)) {
44 E = tempExpr->getSubExpr();
47 if (
auto *tempExpr = dyn_cast<CXXConstructExpr>(
E)) {
48 if (
auto *
C = tempExpr->getConstructor()) {
50 return callback(
E,
true);
54 if (
auto *TempExpr = dyn_cast<CXXUnresolvedConstructExpr>(
E)) {
55 if (isSafePtrType(TempExpr->getTypeAsWritten()))
56 return callback(TempExpr,
true);
58 if (
auto *POE = dyn_cast<PseudoObjectExpr>(
E)) {
59 if (
auto *RF = POE->getResultExpr()) {
64 if (
auto *tempExpr = dyn_cast<ParenExpr>(
E)) {
65 E = tempExpr->getSubExpr();
68 if (
auto *OpaqueValue = dyn_cast<OpaqueValueExpr>(
E)) {
69 E = OpaqueValue->getSourceExpr();
72 if (
auto *
Expr = dyn_cast<ConditionalOperator>(
E)) {
78 if (
auto *
cast = dyn_cast<CastExpr>(
E)) {
79 if (StopAtFirstRefCountedObj) {
80 if (
auto *ConversionFunc =
81 dyn_cast_or_null<FunctionDecl>(
cast->getConversionFunction())) {
83 return callback(
E,
true);
85 if (isa<CXXFunctionalCastExpr>(
E) && isSafePtrType(
cast->getType()))
86 return callback(
E,
true);
90 E =
cast->getSubExpr();
93 if (
auto *call = dyn_cast<CallExpr>(
E)) {
94 if (
auto *memberCall = dyn_cast<CXXMemberCallExpr>(call)) {
95 if (
auto *
decl = memberCall->getMethodDecl()) {
97 if (IsGetterOfRefCt && *IsGetterOfRefCt) {
98 E = memberCall->getImplicitObjectArgument();
99 if (StopAtFirstRefCountedObj) {
100 return callback(
E,
true);
107 if (
auto *operatorCall = dyn_cast<CXXOperatorCallExpr>(
E)) {
108 if (
auto *Callee = operatorCall->getDirectCallee()) {
112 ClsName ==
"UniqueRef" || ClsName ==
"WeakPtr" ||
113 ClsName ==
"WeakRef") {
114 if (operatorCall->getNumArgs() == 1) {
115 E = operatorCall->getArg(0);
122 if (call->isCallToStdMove() && call->getNumArgs() == 1) {
127 if (
auto *callee = call->getDirectCallee()) {
129 if (StopAtFirstRefCountedObj)
130 return callback(
E,
true);
136 if (isSafePtrType(callee->getReturnType()))
137 return callback(
E,
true);
140 return callback(
E,
true);
142 if (callee->isInStdNamespace() &&
safeGetName(callee) ==
"forward") {
153 if (Name ==
"__builtin___CFStringMakeConstantString" ||
154 Name ==
"NSClassFromString")
155 return callback(
E,
true);
158 if (
auto *ObjCMsgExpr = dyn_cast<ObjCMessageExpr>(
E)) {
159 if (
auto *
Method = ObjCMsgExpr->getMethodDecl()) {
160 if (isSafePtrType(
Method->getReturnType()))
161 return callback(
E,
true);
163 auto Selector = ObjCMsgExpr->getSelector();
165 if ((NameForFirstSlot ==
"class" || NameForFirstSlot ==
"superclass") &&
167 return callback(
E,
true);
169 if (
auto *ObjCDict = dyn_cast<ObjCDictionaryLiteral>(
E))
170 return callback(ObjCDict,
true);
171 if (
auto *ObjCArray = dyn_cast<ObjCArrayLiteral>(
E))
172 return callback(ObjCArray,
true);
173 if (
auto *ObjCStr = dyn_cast<ObjCStringLiteral>(
E))
174 return callback(ObjCStr,
true);
175 if (
auto *unaryOp = dyn_cast<UnaryOperator>(
E)) {
177 E = unaryOp->getSubExpr();
180 if (
auto *BoxedExpr = dyn_cast<ObjCBoxedExpr>(
E)) {
181 E = BoxedExpr->getSubExpr();
187 return callback(
E,
false);
192 if (
auto *Ref = dyn_cast<DeclRefExpr>(
E)) {
193 auto *FoundDecl = Ref->getFoundDecl();
194 if (
auto *
D = dyn_cast_or_null<VarDecl>(FoundDecl)) {
195 if (isa<ParmVarDecl>(
D) ||
D->isLocalVarDecl())
197 if (
auto *ImplicitP = dyn_cast<ImplicitParamDecl>(
D)) {
198 auto Kind = ImplicitP->getParameterKind();
205 }
else if (
auto *BD = dyn_cast_or_null<BindingDecl>(FoundDecl)) {
206 VarDecl *VD = BD->getHoldingVar();
215 return isa<CXXThisExpr>(
E);
219 if (
auto *MCE = dyn_cast<CXXMemberCallExpr>(
E)) {
220 if (
auto *Callee = MCE->getDirectCallee()) {
222 if (Name ==
"get" || Name ==
"ptr")
223 E = MCE->getImplicitObjectArgument();
224 if (isa<CXXConversionDecl>(Callee))
225 E = MCE->getImplicitObjectArgument();
227 }
else if (
auto *OCE = dyn_cast<CXXOperatorCallExpr>(
E)) {
228 if (OCE->getOperator() == OO_Star && OCE->getNumArgs() == 1)
232 if (
auto *ME = dyn_cast<MemberExpr>(
E))
233 D = ME->getMemberDecl();
234 else if (
auto *IVR = dyn_cast<ObjCIvarRefExpr>(
E))
238 auto T =
D->getType();
243 auto *ME = dyn_cast<MemberExpr>(
E);
246 auto *
Base = ME->getBase();
249 if (!isa<CXXThisExpr>(
Base->IgnoreParenCasts()))
251 auto *
D = ME->getMemberDecl();
254 auto T =
D->getType();
259 return result && *result;
266 for (
const Stmt *Child : S->children()) {
267 if (Child && !
Visit(Child))
275 RV = RV->IgnoreParenCasts();
276 if (isa<CXXNullPtrLiteralExpr>(RV))
285 auto *MCE = dyn_cast<CXXMemberCallExpr>(
E);
288 auto *Callee = MCE->getDirectCallee();
291 auto *Body = Callee->getBody();
292 if (!Body || Callee->isVirtualAsWritten())
294 auto [CacheIt, IsNew] =
Cache.insert(std::make_pair(Callee,
false));
297 return CacheIt->second;
enum clang::sema::@1840::IndirectLocalPathEntry::EntryKind Kind
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
Defines the clang::Expr interface and subclasses for C++ expressions.
Represents a C++ struct/union/class.
ConstStmtVisitor - This class implements a simple visitor for Stmt subclasses.
Decl - This represents one declaration (or definition), e.g.
bool isACallToEnsureFn(const Expr *E) const
bool VisitReturnStmt(const ReturnStmt *RS)
bool VisitStmt(const Stmt *S)
This represents one expression.
Expr * IgnoreParenCasts() LLVM_READONLY
Skip past any parentheses and casts which might surround this expression until reaching a fixed point...
A (possibly-)qualified type.
ReturnStmt - This represents a return, optionally of an expression: return; return 4;.
Smart pointer class that efficiently represents Objective-C method names.
StringRef getNameForSlot(unsigned argIndex) const
Retrieve the name at a given position in the selector.
unsigned getNumArgs() const
RetTy Visit(PTR(Stmt) S, ParamTys... P)
Stmt - This represents one statement.
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Represents a variable declaration or definition.
bool isLocalVarDecl() const
Returns true for local variable declarations other than parameters.
const internal::VariadicAllOfMatcher< Decl > decl
Matches declarations.
The JSON file list parser is used to communicate input to InstallAPI.
bool isCtorOfSafePtr(const clang::FunctionDecl *F)
bool isExprToGetCheckedPtrCapableMember(const clang::Expr *E)
bool isPtrConversion(const FunctionDecl *F)
std::optional< bool > isCheckedPtrCapable(const clang::CXXRecordDecl *R)
bool tryToFindPtrOrigin(const Expr *E, bool StopAtFirstRefCountedObj, std::function< bool(const clang::CXXRecordDecl *)> isSafePtr, std::function< bool(const clang::QualType)> isSafePtrType, std::function< bool(const clang::Expr *, bool)> callback)
This function de-facto defines a set of transformations that we consider safe (in heuristical sense).
bool isASafeCallArg(const Expr *E)
For E referring to a ref-countable/-counted pointer/reference we return whether it's a safe call argu...
bool isSingleton(const FunctionDecl *F)
bool isRefCounted(const CXXRecordDecl *R)
bool isOwnerPtrType(const clang::QualType T)
std::optional< bool > isGetterOfSafePtr(const CXXMethodDecl *M)
bool isRefType(const std::string &Name)
const FunctionProtoType * T
bool isSafePtr(clang::CXXRecordDecl *Decl)
std::string safeGetName(const T *ASTNode)
bool isCheckedPtr(const std::string &Name)
U cast(CodeGen::Address addr)
@ Class
The "class" keyword introduces the elaborated-type-specifier.
@ CXXThis
Parameter for C++ 'this' argument.
@ CXXVTT
Parameter for C++ virtual table pointers.
@ ObjCSelf
Parameter for Objective-C 'self' argument.
@ ObjCCmd
Parameter for Objective-C '_cmd' argument.
bool isConstOwnerPtrMemberExpr(const clang::Expr *E)
bool isRetainPtr(const std::string &Name)
int const char * function