Skip to content

Commit f63da47

Browse files
authored
[analyzer] Fix an implicit cast to a base ref counted class generates a false positive. (llvm#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()"
1 parent 9df7189 commit f63da47

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ std::optional<bool> isRefCountable(const CXXRecordDecl* R)
8484
if (AnyInconclusiveBase)
8585
return std::nullopt;
8686

87+
Paths.clear();
8788
const auto hasPublicDerefInBase =
8889
[&AnyInconclusiveBase](const CXXBaseSpecifier *Base, CXXBasePath &) {
8990
auto hasDerefInBase = clang::hasPublicMethodInBase(Base, "deref");
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// RUN: %clang_analyze_cc1 -analyzer-checker=alpha.webkit.UncountedCallArgsChecker -verify %s
2+
// expected-no-diagnostics
3+
4+
#include "mock-types.h"
5+
6+
class Base {
7+
public:
8+
virtual ~Base();
9+
void ref() const;
10+
void deref() const;
11+
};
12+
13+
class Event : public Base {
14+
protected:
15+
explicit Event();
16+
};
17+
18+
class SubEvent : public Event {
19+
public:
20+
static Ref<SubEvent> create();
21+
private:
22+
SubEvent() = default;
23+
};
24+
25+
void someFunction(Base&);
26+
27+
static void test()
28+
{
29+
someFunction(SubEvent::create());
30+
}

0 commit comments

Comments
 (0)