Skip to content

Commit 2dbfa84

Browse files
authored
[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.
1 parent f63da47 commit 2dbfa84

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
@@ -91,6 +91,9 @@ class UncountedCallArgsChecker
9191

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

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

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)