[clang] 3500cc8 - [analyzer] RetainCountChecker: Add a suppression for OSSymbols.

Artem Dergachev via cfe-commits cfe-commits at lists.llvm.org
Wed Apr 1 08:17:01 PDT 2020


Author: Artem Dergachev
Date: 2020-04-01T18:16:44+03:00
New Revision: 3500cc8d891bb3825bb3275affe6db8b12f2f695

URL: https://github.com/llvm/llvm-project/commit/3500cc8d891bb3825bb3275affe6db8b12f2f695
DIFF: https://github.com/llvm/llvm-project/commit/3500cc8d891bb3825bb3275affe6db8b12f2f695.diff

LOG: [analyzer] RetainCountChecker: Add a suppression for OSSymbols.

OSSymbol objects are particular XNU OSObjects that aren't really
reference-counted. Therefore you cannot do any harm by over- or
under-releasing them.

Added: 
    

Modified: 
    clang/lib/Analysis/RetainSummaryManager.cpp
    clang/test/Analysis/osobject-retain-release.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Analysis/RetainSummaryManager.cpp b/clang/lib/Analysis/RetainSummaryManager.cpp
index 00bc854a8804..9f45a8efe546 100644
--- a/clang/lib/Analysis/RetainSummaryManager.cpp
+++ b/clang/lib/Analysis/RetainSummaryManager.cpp
@@ -146,7 +146,9 @@ static bool isSubclass(const Decl *D,
 }
 
 static bool isOSObjectSubclass(const Decl *D) {
-  return D && isSubclass(D, "OSMetaClassBase");
+  // OSSymbols are particular OSObjects that are allocated globally
+  // and therefore aren't really refcounted, so we ignore them.
+  return D && isSubclass(D, "OSMetaClassBase") && !isSubclass(D, "OSSymbol");
 }
 
 static bool isOSObjectDynamicCast(StringRef S) {

diff  --git a/clang/test/Analysis/osobject-retain-release.cpp b/clang/test/Analysis/osobject-retain-release.cpp
index 41606a30c39f..d88349dcd807 100644
--- a/clang/test/Analysis/osobject-retain-release.cpp
+++ b/clang/test/Analysis/osobject-retain-release.cpp
@@ -53,6 +53,9 @@ struct MyArray : public OSArray {
   OSObject *generateObject(OSObject *input) override;
 };
 
+// These are never refcounted.
+struct OSSymbol : OSObject {};
+
 struct OtherStruct {
   static void doNothingToArray(OSArray *array);
   OtherStruct(OSArray *arr);
@@ -754,3 +757,10 @@ void test() {
   b(0);
 }
 } // namespace inherited_constructor_crash
+
+namespace ossymbol_suppression {
+OSSymbol *createSymbol();
+void test() {
+  OSSymbol *sym = createSymbol(); // no-warning
+}
+} // namespace ossymbol_suppression


        


More information about the cfe-commits mailing list