Skip to content

Commit 0d0262a

Browse files
rniwahaoNoQ
authored andcommitted
[analyzer] Allow default arguments to be evaluated like other arguments. (llvm#80956)
This PR aligns the evaluation of default arguments with other kinds of arguments by extracting the expressions within them as argument values to be evaluated. (cherry picked from commit 2dbfa84)
1 parent 9e2267f commit 0d0262a

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ class UncountedCallArgsChecker
9292

9393
const auto *Arg = CE->getArg(ArgIdx);
9494

95+
if (auto *defaultArg = dyn_cast<CXXDefaultArgExpr>(Arg))
96+
Arg = defaultArg->getExpr();
97+
9598
std::pair<const clang::Expr *, bool> ArgOrigin =
9699
tryToFindPtrOrigin(Arg, true);
97100

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// RUN: %clang_analyze_cc1 -analyzer-checker=alpha.webkit.UncountedCallArgsChecker -verify %s
2+
3+
#include "mock-types.h"
4+
5+
class Obj {
6+
public:
7+
static Obj* get();
8+
static RefPtr<Obj> create();
9+
void ref() const;
10+
void deref() const;
11+
};
12+
13+
void someFunction(Obj*, Obj* = nullptr);
14+
void otherFunction(Obj*, Obj* = Obj::get());
15+
// expected-warning@-1{{Call argument is uncounted and unsafe [alpha.webkit.UncountedCallArgsChecker]}}
16+
void anotherFunction(Obj*, Obj* = Obj::create().get());
17+
18+
void otherFunction() {
19+
someFunction(nullptr);
20+
someFunction(Obj::get());
21+
// expected-warning@-1{{Call argument is uncounted and unsafe [alpha.webkit.UncountedCallArgsChecker]}}
22+
someFunction(Obj::create().get());
23+
otherFunction(nullptr);
24+
anotherFunction(nullptr);
25+
}

0 commit comments

Comments
 (0)