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);
86 return callback(E,
true);
90 E =
cast->getSubExpr();
93 if (
auto *call = dyn_cast<CallExpr>(E)) {
94 if (
auto *Callee = call->getCalleeDecl()) {
95 if (Callee->hasAttr<CFReturnsRetainedAttr>() ||
96 Callee->hasAttr<NSReturnsRetainedAttr>()) {
97 return callback(E,
true);
101 if (
auto *memberCall = dyn_cast<CXXMemberCallExpr>(call)) {
102 if (
auto *
decl = memberCall->getMethodDecl()) {
104 if (IsGetterOfRefCt && *IsGetterOfRefCt) {
105 E = memberCall->getImplicitObjectArgument();
106 if (StopAtFirstRefCountedObj) {
107 return callback(E,
true);
114 if (
auto *operatorCall = dyn_cast<CXXOperatorCallExpr>(E)) {
115 if (
auto *Callee = operatorCall->getDirectCallee()) {
119 ClsName ==
"UniqueRef" || ClsName ==
"WeakPtr" ||
120 ClsName ==
"WeakRef") {
121 if (operatorCall->getNumArgs() == 1) {
122 E = operatorCall->getArg(0);
129 if (call->isCallToStdMove() && call->getNumArgs() == 1) {
134 if (
auto *callee = call->getDirectCallee()) {
136 if (StopAtFirstRefCountedObj)
137 return callback(E,
true);
143 if (isSafePtrType(callee->getReturnType()))
144 return callback(E,
true);
147 return callback(E,
true);
149 if (callee->isInStdNamespace() &&
safeGetName(callee) ==
"forward") {
160 if (Name ==
"__builtin___CFStringMakeConstantString" ||
161 Name ==
"NSClassFromString")
162 return callback(E,
true);
163 }
else if (
auto *CalleeE = call->getCallee()) {
164 if (
auto *E = dyn_cast<DeclRefExpr>(CalleeE->IgnoreParenCasts())) {
166 return callback(E,
true);
173 if (
auto *CalleeDecl = call->getCalleeDecl()) {
174 if (
auto *FD = dyn_cast<FunctionDecl>(CalleeDecl)) {
175 auto RetType = FD->getReturnType();
176 if (
auto *Subst = dyn_cast<SubstTemplateTypeParmType>(RetType)) {
177 if (
auto *SubstType = Subst->desugar().getTypePtr()) {
178 if (
auto *RD = dyn_cast<RecordType>(SubstType)) {
179 if (
auto *
CXX = dyn_cast<CXXRecordDecl>(RD->getOriginalDecl()))
181 return callback(E,
true);
188 if (
auto *ObjCMsgExpr = dyn_cast<ObjCMessageExpr>(E)) {
189 if (
auto *
Method = ObjCMsgExpr->getMethodDecl()) {
190 if (isSafePtrType(
Method->getReturnType()))
191 return callback(E,
true);
193 auto Selector = ObjCMsgExpr->getSelector();
195 if ((NameForFirstSlot ==
"class" || NameForFirstSlot ==
"superclass") &&
197 return callback(E,
true);
199 if (
auto *ObjCDict = dyn_cast<ObjCDictionaryLiteral>(E))
200 return callback(ObjCDict,
true);
201 if (
auto *ObjCArray = dyn_cast<ObjCArrayLiteral>(E))
202 return callback(ObjCArray,
true);
203 if (
auto *ObjCStr = dyn_cast<ObjCStringLiteral>(E))
204 return callback(ObjCStr,
true);
205 if (
auto *unaryOp = dyn_cast<UnaryOperator>(E)) {
207 E = unaryOp->getSubExpr();
210 if (
auto *BoxedExpr = dyn_cast<ObjCBoxedExpr>(E)) {
211 E = BoxedExpr->getSubExpr();
217 return callback(E,
false);