Skip to content

Commit bc6988f

Browse files
committed
[alpha.webkit.ForwardDeclChecker] Ignore unary operator when detecting a parameter
This PR updates the forward declaration checker so that unary operator & and * will be ignored for the purpose of determining if a given function argument is also a function argument of the caller / call-site.
1 parent 77a3d43 commit bc6988f

File tree

2 files changed

+27
-7
lines changed

2 files changed

+27
-7
lines changed

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

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -263,18 +263,30 @@ class ForwardDeclChecker : public Checker<check::ASTDecl<TranslationUnitDecl>> {
263263
void visitCallArg(const Expr *Arg, const ParmVarDecl *Param,
264264
const Decl *DeclWithIssue) const {
265265
auto *ArgExpr = Arg->IgnoreParenCasts();
266-
if (auto *InnerCE = dyn_cast<CallExpr>(Arg)) {
267-
auto *InnerCallee = InnerCE->getDirectCallee();
268-
if (InnerCallee && InnerCallee->isInStdNamespace() &&
269-
safeGetName(InnerCallee) == "move" && InnerCE->getNumArgs() == 1) {
270-
ArgExpr = InnerCE->getArg(0);
271-
if (ArgExpr)
272-
ArgExpr = ArgExpr->IgnoreParenCasts();
266+
while (ArgExpr) {
267+
ArgExpr = ArgExpr->IgnoreParenCasts();
268+
if (auto *InnerCE = dyn_cast<CallExpr>(ArgExpr)) {
269+
auto *InnerCallee = InnerCE->getDirectCallee();
270+
if (InnerCallee && InnerCallee->isInStdNamespace() &&
271+
safeGetName(InnerCallee) == "move" && InnerCE->getNumArgs() == 1) {
272+
ArgExpr = InnerCE->getArg(0);
273+
continue;
274+
}
275+
}
276+
if (auto *UO = dyn_cast<UnaryOperator>(ArgExpr)) {
277+
auto OpCode = UO->getOpcode();
278+
if (OpCode == UO_Deref || OpCode == UO_AddrOf) {
279+
ArgExpr = UO->getSubExpr();
280+
continue;
281+
}
273282
}
283+
break;
274284
}
285+
275286
if (isNullPtr(ArgExpr) || isa<IntegerLiteral>(ArgExpr) ||
276287
isa<CXXDefaultArgExpr>(ArgExpr))
277288
return;
289+
278290
if (auto *DRE = dyn_cast<DeclRefExpr>(ArgExpr)) {
279291
if (auto *ValDecl = DRE->getDecl()) {
280292
if (isa<ParmVarDecl>(ValDecl))

clang/test/Analysis/Checkers/WebKit/forward-decl-checker.mm

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
Obj* provide_obj_ptr();
1313
void receive_obj_ptr(Obj* p = nullptr);
14+
void receive_obj_ref(Obj&);
15+
void receive_obj_rref(Obj&&);
1416
sqlite3* open_db();
1517
void close_db(sqlite3*);
1618

@@ -38,6 +40,12 @@
3840
return obj;
3941
}
4042

43+
void opaque_call_arg(Obj* obj, Obj&& otherObj) {
44+
receive_obj_ref(*obj);
45+
receive_obj_ptr(&*obj);
46+
receive_obj_rref(std::move(otherObj));
47+
}
48+
4149
Obj&& provide_obj_rval();
4250
void receive_obj_rval(Obj&& p);
4351

0 commit comments

Comments
 (0)