Skip to content

[alpha.webkit.NoUnretainedMemberChecker] Ignore system-header-defined ivar / property of a forward declared type #133755

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 31, 2025

Conversation

rniwa
Copy link
Contributor

@rniwa rniwa commented Mar 31, 2025

Prior to this PR, we were emitting warnings for Objective-C ivars and properties if the forward declaration of the type appeared first in a non-system header. This PR fixes the checker so tha we'd ignore ivars and properties defined for a forward declared type.

… ivar / property of a forward declared type

Prior to this PR, we were emitting warnings for Objective-C ivars and properties if the forward declaration of
the type appeared first in a non-system header. This PR fixes the checker so tha we'd ignore ivars and properties
defined for a forward declared type.
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:static analyzer labels Mar 31, 2025
@rniwa rniwa requested a review from t-rasmud March 31, 2025 17:15
@llvmbot
Copy link
Member

llvmbot commented Mar 31, 2025

@llvm/pr-subscribers-clang-static-analyzer-1

@llvm/pr-subscribers-clang

Author: Ryosuke Niwa (rniwa)

Changes

Prior to this PR, we were emitting warnings for Objective-C ivars and properties if the forward declaration of the type appeared first in a non-system header. This PR fixes the checker so tha we'd ignore ivars and properties defined for a forward declared type.


Full diff: https://github.com/llvm/llvm-project/pull/133755.diff

2 Files Affected:

  • (modified) clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefMemberChecker.cpp (+5)
  • (modified) clang/test/Analysis/Checkers/WebKit/unretained-members.mm (+2)
diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefMemberChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefMemberChecker.cpp
index 89df1a725ab92..233bd8471bf89 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefMemberChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefMemberChecker.cpp
@@ -133,6 +133,8 @@ class RawPtrRefMemberChecker
 
   void visitIvarDecl(const ObjCContainerDecl *CD,
                      const ObjCIvarDecl *Ivar) const {
+    if (BR->getSourceManager().isInSystemHeader(Ivar->getLocation()))
+      return;
     auto QT = Ivar->getType();
     const Type *IvarType = QT.getTypePtrOrNull();
     if (!IvarType)
@@ -154,6 +156,8 @@ class RawPtrRefMemberChecker
 
   void visitObjCPropertyDecl(const ObjCContainerDecl *CD,
                              const ObjCPropertyDecl *PD) const {
+    if (BR->getSourceManager().isInSystemHeader(PD->getLocation()))
+      return;
     auto QT = PD->getType();
     const Type *PropType = QT.getTypePtrOrNull();
     if (!PropType)
@@ -241,6 +245,7 @@ class RawPtrRefMemberChecker
                                  BR->getSourceManager());
     auto Report = std::make_unique<BasicBugReport>(Bug, Os.str(), BSLoc);
     Report->addRange(Member->getSourceRange());
+    Report->setDeclWithIssue(ClassCXXRD);
     BR->emitReport(std::move(Report));
   }
 
diff --git a/clang/test/Analysis/Checkers/WebKit/unretained-members.mm b/clang/test/Analysis/Checkers/WebKit/unretained-members.mm
index 92d70a94427c0..fff1f8ede091b 100644
--- a/clang/test/Analysis/Checkers/WebKit/unretained-members.mm
+++ b/clang/test/Analysis/Checkers/WebKit/unretained-members.mm
@@ -1,5 +1,7 @@
 // RUN: %clang_analyze_cc1 -analyzer-checker=alpha.webkit.NoUnretainedMemberChecker -verify %s
 
+@class SystemObject;
+
 #include "objc-mock-types.h"
 #include "mock-system-header.h"
 

Copy link
Contributor

@t-rasmud t-rasmud left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@rniwa
Copy link
Contributor Author

rniwa commented Mar 31, 2025

Thanks for the quick review!

@rniwa rniwa merged commit 6ff33ed into llvm:main Mar 31, 2025
11 checks passed
rniwa added a commit to rniwa/llvm-project that referenced this pull request Mar 31, 2025
… ivar / property of a forward declared type (llvm#133755)

Prior to this PR, we were emitting warnings for Objective-C ivars and
properties if the forward declaration of the type appeared first in a
non-system header. This PR fixes the checker so tha we'd ignore ivars
and properties defined for a forward declared type.
@rniwa rniwa deleted the fix-webkit-system-header-forward-decl branch April 9, 2025 18:08
rniwa added a commit to rniwa/llvm-project that referenced this pull request Apr 22, 2025
… ivar / property of a forward declared type (llvm#133755)

Prior to this PR, we were emitting warnings for Objective-C ivars and
properties if the forward declaration of the type appeared first in a
non-system header. This PR fixes the checker so tha we'd ignore ivars
and properties defined for a forward declared type.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:static analyzer clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants