[clang] f63da47 - [analyzer] Fix an implicit cast to a base ref counted class generates a false positive. (#80934)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Feb 12 15:01:19 PST 2024
Author: Ryosuke Niwa
Date: 2024-02-12T15:01:16-08:00
New Revision: f63da479ae2f5e0d747430f268ae7b458c02455c
URL: https://github.com/llvm/llvm-project/commit/f63da479ae2f5e0d747430f268ae7b458c02455c
DIFF: https://github.com/llvm/llvm-project/commit/f63da479ae2f5e0d747430f268ae7b458c02455c.diff
LOG: [analyzer] Fix an implicit cast to a base ref counted class generates a false positive. (#80934)
The bug was caused by isRefCountable erroneously returning false for a
class with both ref() and deref() functions defined because we were not
resetting the base paths results between looking for "ref()" and
"deref()"
Added:
clang/test/Analysis/Checkers/WebKit/implicit-cast-to-base-class-with-deref-in-superclass.cpp
Modified:
clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
Removed:
################################################################################
diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
index eadd4686e5dfc3..96784d42d09fa4 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
@@ -84,6 +84,7 @@ std::optional<bool> isRefCountable(const CXXRecordDecl* R)
if (AnyInconclusiveBase)
return std::nullopt;
+ Paths.clear();
const auto hasPublicDerefInBase =
[&AnyInconclusiveBase](const CXXBaseSpecifier *Base, CXXBasePath &) {
auto hasDerefInBase = clang::hasPublicMethodInBase(Base, "deref");
diff --git a/clang/test/Analysis/Checkers/WebKit/implicit-cast-to-base-class-with-deref-in-superclass.cpp b/clang/test/Analysis/Checkers/WebKit/implicit-cast-to-base-class-with-deref-in-superclass.cpp
new file mode 100644
index 00000000000000..176238f31bd2e4
--- /dev/null
+++ b/clang/test/Analysis/Checkers/WebKit/implicit-cast-to-base-class-with-deref-in-superclass.cpp
@@ -0,0 +1,30 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=alpha.webkit.UncountedCallArgsChecker -verify %s
+// expected-no-diagnostics
+
+#include "mock-types.h"
+
+class Base {
+public:
+ virtual ~Base();
+ void ref() const;
+ void deref() const;
+};
+
+class Event : public Base {
+protected:
+ explicit Event();
+};
+
+class SubEvent : public Event {
+public:
+ static Ref<SubEvent> create();
+private:
+ SubEvent() = default;
+};
+
+void someFunction(Base&);
+
+static void test()
+{
+ someFunction(SubEvent::create());
+}
More information about the cfe-commits
mailing list