File tree Expand file tree Collapse file tree
lib/StaticAnalyzer/Checkers/WebKit
test/Analysis/Checkers/WebKit Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -120,6 +120,14 @@ class RawPtrRefCallArgsChecker
120120 if (auto *MemberCallExpr = dyn_cast<CXXMemberCallExpr>(CE ))
121121 checkThisArg (MemberCallExpr, D);
122122
123+ if (ArgIdx) {
124+ auto *Arg = CE ->getArg (0 );
125+ QualType ArgType = Arg->getType ().getCanonicalType ();
126+ std::optional<bool > IsUnsafe = isUnsafeType (ArgType);
127+ if (IsUnsafe && *IsUnsafe && !isPtrOriginSafe (Arg))
128+ reportBugOnThis (Arg, D);
129+ }
130+
123131 for (auto P = F->param_begin ();
124132 P < F->param_end () && ArgIdx < CE ->getNumArgs (); ++P, ++ArgIdx) {
125133 // TODO: attributes.
Original file line number Diff line number Diff line change @@ -330,18 +330,30 @@ namespace cxx_member_operator_call {
330330 Foo& operator +(RefCountable* bad);
331331 friend Foo& operator -(Foo& lhs, RefCountable* bad);
332332 void operator ()(RefCountable* bad);
333+ int operator [](unsigned i);
333334 };
334335
335336 RefCountable* global;
336337
337- void foo () {
338+ struct Container : public RefCountable {
339+ int m[4 ];
340+ int & operator [](unsigned i) {
341+ some_function ();
342+ return m[i];
343+ }
344+ };
345+ Container container ();
346+
347+ void foo12 () {
338348 Foo f;
339349 f + global;
340350 // expected-warning@-1{{Call argument for parameter 'bad' is uncounted and unsafe}}
341351 f - global;
342352 // expected-warning@-1{{Call argument for parameter 'bad' is uncounted and unsafe}}
343353 f (global);
344354 // expected-warning@-1{{Call argument for parameter 'bad' is uncounted and unsafe}}
355+ container ()[0 ] = 3 ;
356+ // expected-warning@-1{{Call argument for 'this' parameter is uncounted and unsafe}}
345357 }
346358}
347359
Original file line number Diff line number Diff line change @@ -480,14 +480,14 @@ class RefCounted {
480480
481481 int nonTrivial13 () { return ~otherFunction (); }
482482 int nonTrivial14 () { int r = 0xff ; r |= otherFunction (); return r; }
483- void nonTrivial15 () { ++complex ; }
484- void nonTrivial16 () { complex ++; }
483+ void nonTrivial15 () { ++complex ; } // expected-warning{{Call argument for 'this' parameter is uncounted and unsafe}}
484+ void nonTrivial16 () { complex ++; } // expected-warning{{Call argument for 'this' parameter is uncounted and unsafe}}
485485 ComplexNumber nonTrivial17 () {
486- return complex << 2 ;
486+ return complex << 2 ; // expected-warning{{Call argument for 'this' parameter is uncounted and unsafe}}
487487 // expected-warning@-1{{Call argument is uncounted and unsafe}}
488488 }
489489 ComplexNumber nonTrivial18 () {
490- return +complex ;
490+ return +complex ; // expected-warning{{Call argument for 'this' parameter is uncounted and unsafe}}
491491 // expected-warning@-1{{Call argument is uncounted and unsafe}}
492492 }
493493 ComplexNumber* nonTrivial19 () {
You can’t perform that action at this time.
0 commit comments