Skip to content

Commit 9353d0d

Browse files
authored
[alpha.webkit.UncountedCallArgsChecker] Check CXXOperatorCallExpr's this argument (llvm#198688)
This PR fixes the bug that we were not checking "this" parameter of CXXOperatorCallExpr.
1 parent e90ae13 commit 9353d0d

3 files changed

Lines changed: 25 additions & 5 deletions

File tree

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff 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.

clang/test/Analysis/Checkers/WebKit/call-args.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff 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

clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff 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() {

0 commit comments

Comments
 (0)