File tree Expand file tree Collapse file tree 6 files changed +73
-0
lines changed
lib/StaticAnalyzer/Checkers/WebKit
test/Analysis/Checkers/WebKit Expand file tree Collapse file tree 6 files changed +73
-0
lines changed Original file line number Diff line number Diff line change @@ -236,6 +236,26 @@ bool isConstOwnerPtrMemberExpr(const clang::Expr *E) {
236
236
return isOwnerPtrType (T) && T.isConstQualified ();
237
237
}
238
238
239
+ bool isExprToGetCheckedPtrCapableMember (const clang::Expr *E) {
240
+ auto *ME = dyn_cast<MemberExpr>(E);
241
+ if (!ME)
242
+ return false ;
243
+ auto *Base = ME->getBase ();
244
+ if (!Base)
245
+ return false ;
246
+ if (!isa<CXXThisExpr>(Base->IgnoreParenCasts ()))
247
+ return false ;
248
+ auto *D = ME->getMemberDecl ();
249
+ if (!D)
250
+ return false ;
251
+ auto T = D->getType ();
252
+ auto *CXXRD = T->getAsCXXRecordDecl ();
253
+ if (!CXXRD)
254
+ return false ;
255
+ auto result = isCheckedPtrCapable (CXXRD);
256
+ return result && *result;
257
+ }
258
+
239
259
class EnsureFunctionVisitor
240
260
: public ConstStmtVisitor<EnsureFunctionVisitor, bool > {
241
261
public:
Original file line number Diff line number Diff line change @@ -69,6 +69,10 @@ bool isASafeCallArg(const clang::Expr *E);
69
69
// / \returns true if E is a MemberExpr accessing a const smart pointer type.
70
70
bool isConstOwnerPtrMemberExpr (const clang::Expr *E);
71
71
72
+ // / \returns true if E is a MemberExpr accessing a member variable which
73
+ // / supports CheckedPtr.
74
+ bool isExprToGetCheckedPtrCapableMember (const clang::Expr *E);
75
+
72
76
// / \returns true if E is a CXXMemberCallExpr which returns a const smart
73
77
// / pointer type.
74
78
class EnsureFunctionAnalysis {
Original file line number Diff line number Diff line change @@ -443,6 +443,10 @@ class UncheckedCallArgsChecker final : public RawPtrRefCallArgsChecker {
443
443
return isRefOrCheckedPtrType (type);
444
444
}
445
445
446
+ bool isSafeExpr (const Expr *E) const final {
447
+ return isExprToGetCheckedPtrCapableMember (E);
448
+ }
449
+
446
450
const char *ptrKind () const final { return " unchecked" ; }
447
451
};
448
452
Original file line number Diff line number Diff line change @@ -417,6 +417,9 @@ class UncheckedLocalVarsChecker final : public RawPtrRefLocalVarsChecker {
417
417
bool isSafePtrType (const QualType type) const final {
418
418
return isRefOrCheckedPtrType (type);
419
419
}
420
+ bool isSafeExpr (const Expr *E) const final {
421
+ return isExprToGetCheckedPtrCapableMember (E);
422
+ }
420
423
const char *ptrKind () const final { return " unchecked" ; }
421
424
};
422
425
Original file line number Diff line number Diff line change @@ -46,6 +46,26 @@ static void baz() {
46
46
47
47
} // namespace call_args_checked
48
48
49
+ namespace call_args_member {
50
+
51
+ void consume (CheckedObj&);
52
+
53
+ struct WrapperObj {
54
+ CheckedObj checked;
55
+ CheckedObj& checkedRef;
56
+ void foo () {
57
+ consume (checked);
58
+ consume (checkedRef);
59
+ // expected-warning@-1{{Call argument is unchecked and unsafe [alpha.webkit.UncheckedCallArgsChecker]}}
60
+ }
61
+ void bar (WrapperObj& other) {
62
+ consume (other.checked );
63
+ // expected-warning@-1{{Call argument is unchecked and unsafe [alpha.webkit.UncheckedCallArgsChecker]}}
64
+ }
65
+ };
66
+
67
+ } // namespace call_args_checked
68
+
49
69
namespace call_args_default {
50
70
51
71
void someFunction (RefCountableAndCheckable* = makeObj());
Original file line number Diff line number Diff line change @@ -290,6 +290,28 @@ void foo() {
290
290
291
291
} // namespace local_assignment_to_global
292
292
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
+ void bar (WrapperObj& wrapper) {
307
+ CheckedObj* ptr = &wrapper.checked ;
308
+ // expected-warning@-1{{Local variable 'ptr' is unchecked and unsafe [alpha.webkit.UncheckedLocalVarsChecker]}}
309
+ ptr->method ();
310
+ }
311
+ };
312
+
313
+ }
314
+
293
315
namespace local_refcountable_checkable_object {
294
316
295
317
RefCountableAndCheckable* provide_obj ();
You can’t perform that action at this time.
0 commit comments