[clang] Add a new attribute value for suppressing WebKit's unsafe member variable warning (PR #70124)

Ryosuke Niwa via cfe-commits cfe-commits at lists.llvm.org
Tue Oct 24 13:53:43 PDT 2023


https://github.com/rniwa created https://github.com/llvm/llvm-project/pull/70124

None

>From 3b420fcb0a6d74dc034cfdf2d7b28e13e75f0e08 Mon Sep 17 00:00:00 2001
From: Ryosuke Niwa <rniwa at webkit.org>
Date: Tue, 24 Oct 2023 13:51:50 -0700
Subject: [PATCH] Add a new attribute value for suppressing WebKit's unsafe
 member variable warning

---
 .../Checkers/WebKit/NoUncountedMembersChecker.cpp          | 7 +++++++
 clang/test/Analysis/Checkers/WebKit/uncounted-members.cpp  | 1 +
 2 files changed, 8 insertions(+)

diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/NoUncountedMembersChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/WebKit/NoUncountedMembersChecker.cpp
index 66d8588e2531589..6f03e4ac27c4613 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/NoUncountedMembersChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/NoUncountedMembersChecker.cpp
@@ -75,6 +75,13 @@ class NoUncountedMemberChecker
       if (!MemberType)
         continue;
 
+      if (std::any_of(
+        Member->specific_attr_begin<AnnotateAttr>(),
+        Member->specific_attr_end<AnnotateAttr>(), [](const AnnotateAttr *Ann) {
+          return Ann->getAnnotation() == "webkit_uncountedmember_exception";
+        }))
+          continue;
+
       if (auto *MemberCXXRD = MemberType->getPointeeCXXRecordDecl()) {
         // If we don't see the definition we just don't know.
         if (MemberCXXRD->hasDefinition()) {
diff --git a/clang/test/Analysis/Checkers/WebKit/uncounted-members.cpp b/clang/test/Analysis/Checkers/WebKit/uncounted-members.cpp
index a0ea61e0e2a13b1..b175f9491ab5b73 100644
--- a/clang/test/Analysis/Checkers/WebKit/uncounted-members.cpp
+++ b/clang/test/Analysis/Checkers/WebKit/uncounted-members.cpp
@@ -16,6 +16,7 @@ namespace members {
     RefCountable& c = silenceWarningAboutInit;
 // expected-warning at -1{{Member variable 'c' in 'members::Foo' is a reference to ref-countable type 'RefCountable'}}
     Ref<RefCountable> d;
+    __attribute__((annotate("webkit_uncountedmember_exception"))) RefCountable* e;
   };
 
   template<class T>



More information about the cfe-commits mailing list