Skip to content

Commit a9c8d85

Browse files
committed
Removed the redundant OCE->getNumArgs() == 2 check in VisitCXXOperatorCallExpr when it's an assignment,
and added tests for ternary expresssion per review comments.
1 parent 075f567 commit a9c8d85

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ struct GuardianVisitor : public RecursiveASTVisitor<GuardianVisitor> {
9595
}
9696

9797
bool VisitCXXOperatorCallExpr(const CXXOperatorCallExpr *OCE) {
98-
if (OCE->isAssignmentOp() && OCE->getNumArgs() == 2) {
98+
if (OCE->isAssignmentOp()) {
99+
assert(OCE->getNumArgs() == 2);
99100
auto *ThisArg = OCE->getArg(0)->IgnoreParenCasts();
100101
if (auto *VarRef = dyn_cast<DeclRefExpr>(ThisArg)) {
101102
if (VarRef->getDecl() == Guardian)

clang/test/Analysis/Checkers/WebKit/uncounted-local-vars.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,12 @@ void foo8(RefCountable* obj) {
111111
foo.releaseNonNull();
112112
bar->method();
113113
}
114+
{
115+
RefCountable *bar = foo.get();
116+
// expected-warning@-1{{Local variable 'bar' is uncounted and unsafe [alpha.webkit.UncountedLocalVarsChecker]}}
117+
foo = obj ? obj : nullptr;
118+
bar->method();
119+
}
114120
}
115121

116122
void foo9(RefCountable& o) {
@@ -140,6 +146,12 @@ void foo9(RefCountable& o) {
140146
guardian.leakRef();
141147
bar->method();
142148
}
149+
{
150+
RefCountable *bar = guardian.ptr();
151+
// expected-warning@-1{{Local variable 'bar' is uncounted and unsafe [alpha.webkit.UncountedLocalVarsChecker]}}
152+
guardian = o.trivial() ? o : *bar;
153+
bar->method();
154+
}
143155
}
144156

145157
} // namespace guardian_scopes

0 commit comments

Comments
 (0)