[clang] 2dbfa84 - [analyzer] Allow default arguments to be evaluated like other arguments. (#80956)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Feb 12 15:01:44 PST 2024
Author: Ryosuke Niwa
Date: 2024-02-12T15:01:40-08:00
New Revision: 2dbfa8407e7d2f4293add33b5ead3f2d5fcd04e9
URL: https://github.com/llvm/llvm-project/commit/2dbfa8407e7d2f4293add33b5ead3f2d5fcd04e9
DIFF: https://github.com/llvm/llvm-project/commit/2dbfa8407e7d2f4293add33b5ead3f2d5fcd04e9.diff
LOG: [analyzer] Allow default arguments to be evaluated like other arguments. (#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.
Added:
clang/test/Analysis/Checkers/WebKit/ref-countable-default-arg-nullptr.cpp
Modified:
clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp
Removed:
################################################################################
diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp
index 737e887b89afd..f4e6191cf05a3 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp
@@ -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);
diff --git a/clang/test/Analysis/Checkers/WebKit/ref-countable-default-arg-nullptr.cpp b/clang/test/Analysis/Checkers/WebKit/ref-countable-default-arg-nullptr.cpp
new file mode 100644
index 0000000000000..a1860a5434c86
--- /dev/null
+++ b/clang/test/Analysis/Checkers/WebKit/ref-countable-default-arg-nullptr.cpp
@@ -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 at -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 at -1{{Call argument is uncounted and unsafe [alpha.webkit.UncountedCallArgsChecker]}}
+ someFunction(Obj::create().get());
+ otherFunction(nullptr);
+ anotherFunction(nullptr);
+}
More information about the cfe-commits
mailing list