File tree Expand file tree Collapse file tree 6 files changed +58
-0
lines changed
lib/StaticAnalyzer/Checkers/WebKit
test/Analysis/Checkers/WebKit Expand file tree Collapse file tree 6 files changed +58
-0
lines changed Original file line number Diff line number Diff line change @@ -231,6 +231,21 @@ bool isConstOwnerPtrMemberExpr(const clang::Expr *E) {
231231 return isOwnerPtrType (T) && T.isConstQualified ();
232232}
233233
234+ bool isExprToGetCheckedPtrCapableMember (const clang::Expr *E) {
235+ auto *ME = dyn_cast<MemberExpr>(E);
236+ if (!ME)
237+ return false ;
238+ auto *D = ME->getMemberDecl ();
239+ if (!D)
240+ return false ;
241+ auto T = D->getType ();
242+ auto *CXXRD = T->getAsCXXRecordDecl ();
243+ if (!CXXRD)
244+ return false ;
245+ auto result = isCheckedPtrCapable (CXXRD);
246+ return result && *result;
247+ }
248+
234249class EnsureFunctionVisitor
235250 : public ConstStmtVisitor<EnsureFunctionVisitor, bool > {
236251public:
Original file line number Diff line number Diff line change @@ -69,6 +69,10 @@ bool isASafeCallArg(const clang::Expr *E);
6969// / \returns true if E is a MemberExpr accessing a const smart pointer type.
7070bool isConstOwnerPtrMemberExpr (const clang::Expr *E);
7171
72+ // / \returns true if E is a MemberExpr accessing a member variable which
73+ // / supports CheckedPtr.
74+ bool isExprToGetCheckedPtrCapableMember (const clang::Expr *E);
75+
7276// / \returns true if E is a CXXMemberCallExpr which returns a const smart
7377// / pointer type.
7478class EnsureFunctionAnalysis {
Original file line number Diff line number Diff line change @@ -443,6 +443,10 @@ class UncheckedCallArgsChecker final : public RawPtrRefCallArgsChecker {
443443 return isRefOrCheckedPtrType (type);
444444 }
445445
446+ bool isSafeExpr (const Expr *E) const final {
447+ return isExprToGetCheckedPtrCapableMember (E);
448+ }
449+
446450 const char *ptrKind () const final { return " unchecked" ; }
447451};
448452
Original file line number Diff line number Diff line change @@ -417,6 +417,9 @@ class UncheckedLocalVarsChecker final : public RawPtrRefLocalVarsChecker {
417417 bool isSafePtrType (const QualType type) const final {
418418 return isRefOrCheckedPtrType (type);
419419 }
420+ bool isSafeExpr (const Expr *E) const final {
421+ return isExprToGetCheckedPtrCapableMember (E);
422+ }
420423 const char *ptrKind () const final { return " unchecked" ; }
421424};
422425
Original file line number Diff line number Diff line change @@ -32,6 +32,22 @@ static void baz() {
3232
3333} // namespace call_args_checked
3434
35+ namespace call_args_member {
36+
37+ void consume (CheckedObj&);
38+
39+ struct WrapperObj {
40+ CheckedObj checked;
41+ CheckedObj& checkedRef;
42+ void foo () {
43+ consume (checked);
44+ consume (checkedRef);
45+ // expected-warning@-1{{Call argument is unchecked and unsafe [alpha.webkit.UncheckedCallArgsChecker]}}
46+ }
47+ };
48+
49+ } // namespace call_args_checked
50+
3551namespace call_args_default {
3652
3753void someFunction (RefCountableAndCheckable* = makeObj());
Original file line number Diff line number Diff line change @@ -290,6 +290,22 @@ void foo() {
290290
291291} // namespace local_assignment_to_global
292292
293+ namespace member_var {
294+
295+ struct WrapperObj {
296+ CheckedObj checked;
297+ CheckedObj& checkedRef;
298+ void foo () {
299+ auto *a = &checked;
300+ a->method ();
301+ auto *b = &checkedRef;
302+ // expected-warning@-1{{Local variable 'b' is unchecked and unsafe [alpha.webkit.UncheckedLocalVarsChecker]}}
303+ b->method ();
304+ }
305+ };
306+
307+ }
308+
293309namespace local_refcountable_checkable_object {
294310
295311RefCountableAndCheckable* provide_obj ();
You can’t perform that action at this time.
0 commit comments