[clang] [webkit.NoUncountedMemberChecker] Fix a regression that every class is treated as if it's ref countable. (PR #131249)
Ryosuke Niwa via cfe-commits
cfe-commits at lists.llvm.org
Thu Mar 13 18:14:13 PDT 2025
https://github.com/rniwa created https://github.com/llvm/llvm-project/pull/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.
>From f6046b47b8897310ebb46e028641cf59cb11de7e Mon Sep 17 00:00:00 2001
From: Ryosuke Niwa <rniwa at webkit.org>
Date: Thu, 13 Mar 2025 18:08:38 -0700
Subject: [PATCH] [webkit.NoUncountedMemberChecker] Fix a regression that every
class is treated as if it's ref countable.
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.
---
.../Checkers/WebKit/RawPtrRefMemberChecker.cpp | 4 ++--
.../Analysis/Checkers/WebKit/uncounted-members.cpp | 10 +++++++++-
2 files changed, 11 insertions(+), 3 deletions(-)
diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefMemberChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefMemberChecker.cpp
index 593e6e3663639..dc4e2c7d168fb 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefMemberChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefMemberChecker.cpp
@@ -223,7 +223,7 @@ class NoUncountedMemberChecker final : public RawPtrRefMemberChecker {
std::optional<bool>
isPtrCompatible(const clang::QualType,
const clang::CXXRecordDecl *R) const final {
- return R && isRefCountable(R);
+ return R ? isRefCountable(R) : std::nullopt;
}
bool isPtrCls(const clang::CXXRecordDecl *R) const final {
@@ -246,7 +246,7 @@ class NoUncheckedPtrMemberChecker final : public RawPtrRefMemberChecker {
std::optional<bool>
isPtrCompatible(const clang::QualType,
const clang::CXXRecordDecl *R) const final {
- return R && isCheckedPtrCapable(R);
+ return R ? isCheckedPtrCapable(R) : std::nullopt;
}
bool isPtrCls(const clang::CXXRecordDecl *R) const final {
diff --git a/clang/test/Analysis/Checkers/WebKit/uncounted-members.cpp b/clang/test/Analysis/Checkers/WebKit/uncounted-members.cpp
index bca7b3bad3a15..1bdbaedefbfeb 100644
--- a/clang/test/Analysis/Checkers/WebKit/uncounted-members.cpp
+++ b/clang/test/Analysis/Checkers/WebKit/uncounted-members.cpp
@@ -36,7 +36,6 @@ namespace members {
};
}
-
namespace ignore_unions {
union Foo {
RefCountable* a;
@@ -60,3 +59,12 @@ void foo(RefCountable* t) {
}
} // ignore_system_header
+
+namespace ignore_non_ref_countable {
+ struct Foo {
+ };
+
+ struct Bar {
+ Foo* foo;
+ };
+}
\ No newline at end of file
More information about the cfe-commits
mailing list