Skip to content

Commit 7806a15

Browse files
committed
Use early returns instead of nested if's per review comment
1 parent a9e526e commit 7806a15

File tree

1 file changed

+35
-26
lines changed

1 file changed

+35
-26
lines changed

clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLambdaCapturesChecker.cpp

Lines changed: 35 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,14 @@ class UncountedLambdaCapturesChecker
5252
bool VisitDeclRefExpr(DeclRefExpr *DRE) {
5353
if (DeclRefExprsToIgnore.contains(DRE))
5454
return true;
55-
if (auto *VD = dyn_cast_or_null<VarDecl>(DRE->getDecl())) {
56-
auto *Init = VD->getInit()->IgnoreParenCasts();
57-
if (auto *L = dyn_cast_or_null<LambdaExpr>(Init)) {
58-
Checker->visitLambdaExpr(L);
59-
return true;
60-
}
61-
}
55+
auto *VD = dyn_cast_or_null<VarDecl>(DRE->getDecl());
56+
if (!VD)
57+
return true;
58+
auto *Init = VD->getInit()->IgnoreParenCasts();
59+
auto *L = dyn_cast_or_null<LambdaExpr>(Init);
60+
if (!L)
61+
return true;
62+
Checker->visitLambdaExpr(L);
6263
return true;
6364
}
6465

@@ -72,25 +73,7 @@ class UncountedLambdaCapturesChecker
7273
}
7374

7475
bool VisitCallExpr(CallExpr *CE) {
75-
if (auto *Callee = CE->getCallee()) {
76-
if (auto *DRE = dyn_cast<DeclRefExpr>(Callee->IgnoreParenCasts())) {
77-
if (auto *MD = dyn_cast_or_null<CXXMethodDecl>(DRE->getDecl())) {
78-
if (CE->getNumArgs() == 1) {
79-
auto *Arg = CE->getArg(0)->IgnoreParenCasts();
80-
if (auto *DRE = dyn_cast<DeclRefExpr>(Arg)) {
81-
if (auto *VD = dyn_cast_or_null<VarDecl>(DRE->getDecl())) {
82-
auto *Init = VD->getInit()->IgnoreParenCasts();
83-
if (auto *L = dyn_cast_or_null<LambdaExpr>(Init)) {
84-
DeclRefExprsToIgnore.insert(DRE);
85-
Checker->visitLambdaExpr(L,
86-
/* ignoreParamVarDecl */ true);
87-
}
88-
}
89-
}
90-
}
91-
}
92-
}
93-
}
76+
checkCalleeLambda(CE);
9477
if (auto *Callee = CE->getDirectCallee()) {
9578
bool TreatAllArgsAsNoEscape = shouldTreatAllArgAsNoEscape(Callee);
9679
unsigned ArgIndex = 0;
@@ -107,6 +90,32 @@ class UncountedLambdaCapturesChecker
10790
}
10891
return true;
10992
}
93+
94+
void checkCalleeLambda(CallExpr *CE) {
95+
auto* Callee = CE->getCallee();
96+
if (!Callee)
97+
return;
98+
auto *DRE = dyn_cast<DeclRefExpr>(Callee->IgnoreParenCasts());
99+
if (!DRE)
100+
return;
101+
auto *MD = dyn_cast_or_null<CXXMethodDecl>(DRE->getDecl());
102+
if (!MD || CE->getNumArgs() != 1)
103+
return;
104+
auto *Arg = CE->getArg(0)->IgnoreParenCasts();
105+
auto *ArgRef = dyn_cast<DeclRefExpr>(Arg);
106+
if (!ArgRef)
107+
return;
108+
auto *VD = dyn_cast_or_null<VarDecl>(ArgRef->getDecl());
109+
if (!VD)
110+
return;
111+
auto *Init = VD->getInit()->IgnoreParenCasts();
112+
auto *L = dyn_cast_or_null<LambdaExpr>(Init);
113+
if (!L)
114+
return;
115+
DeclRefExprsToIgnore.insert(ArgRef);
116+
Checker->visitLambdaExpr(L, /* ignoreParamVarDecl */ true);
117+
}
118+
110119
};
111120

112121
LocalVisitor visitor(this);

0 commit comments

Comments
 (0)