Skip to content

Commit 512354d

Browse files
committed
[webkit.NoUncountedMemberChecker] Fix a regression that every class is treated as if it's ref countable. (llvm#131249)
This PR fixes a regression that webkit.NoUncountedMemberChecker and alpha.webkit.NoUncheckedMemberChecker emits warnings for every class as if they supported ref counting and checked ptr because we were erroneously coercing the return value of isRefCountable and isCheckedPtrCapable, which is std::optional<bool>, to boolean values.
1 parent 91946d8 commit 512354d

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ class NoUncountedMemberChecker final : public RawPtrRefMemberChecker {
224224
std::optional<bool>
225225
isPtrCompatible(const clang::QualType,
226226
const clang::CXXRecordDecl *R) const final {
227-
return R && isRefCountable(R);
227+
return R ? isRefCountable(R) : std::nullopt;
228228
}
229229

230230
bool isPtrCls(const clang::CXXRecordDecl *R) const final {
@@ -247,7 +247,7 @@ class NoUncheckedPtrMemberChecker final : public RawPtrRefMemberChecker {
247247
std::optional<bool>
248248
isPtrCompatible(const clang::QualType,
249249
const clang::CXXRecordDecl *R) const final {
250-
return R && isCheckedPtrCapable(R);
250+
return R ? isCheckedPtrCapable(R) : std::nullopt;
251251
}
252252

253253
bool isPtrCls(const clang::CXXRecordDecl *R) const final {

clang/test/Analysis/Checkers/WebKit/uncounted-members.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ namespace members {
3636
};
3737
}
3838

39-
4039
namespace ignore_unions {
4140
union Foo {
4241
RefCountable* a;
@@ -60,3 +59,12 @@ void foo(RefCountable* t) {
6059
}
6160

6261
} // ignore_system_header
62+
63+
namespace ignore_non_ref_countable {
64+
struct Foo {
65+
};
66+
67+
struct Bar {
68+
Foo* foo;
69+
};
70+
}

0 commit comments

Comments
 (0)