Skip to content

Commit

Permalink
[analyzer] Allow default arguments to be evaluated like other argumen…
Browse files Browse the repository at this point in the history
…ts. (#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.
  • Loading branch information
rniwa committed Feb 12, 2024
1 parent f63da47 commit 2dbfa84
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ class UncountedCallArgsChecker

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

if (auto *defaultArg = dyn_cast<CXXDefaultArgExpr>(Arg))
Arg = defaultArg->getExpr();

std::pair<const clang::Expr *, bool> ArgOrigin =
tryToFindPtrOrigin(Arg, true);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// RUN: %clang_analyze_cc1 -analyzer-checker=alpha.webkit.UncountedCallArgsChecker -verify %s

#include "mock-types.h"

class Obj {
public:
static Obj* get();
static RefPtr<Obj> create();
void ref() const;
void deref() const;
};

void someFunction(Obj*, Obj* = nullptr);
void otherFunction(Obj*, Obj* = Obj::get());
// expected-warning@-1{{Call argument is uncounted and unsafe [alpha.webkit.UncountedCallArgsChecker]}}
void anotherFunction(Obj*, Obj* = Obj::create().get());

void otherFunction() {
someFunction(nullptr);
someFunction(Obj::get());
// expected-warning@-1{{Call argument is uncounted and unsafe [alpha.webkit.UncountedCallArgsChecker]}}
someFunction(Obj::create().get());
otherFunction(nullptr);
anotherFunction(nullptr);
}

0 comments on commit 2dbfa84

Please sign in to comment.