]> granicus.if.org Git - clang/commitdiff
[Analyzer] More granular special casing in RetainCountChecker
authorGeorge Karpenkov <ekarpenkov@apple.com>
Tue, 3 Oct 2017 18:12:15 +0000 (18:12 +0000)
committerGeorge Karpenkov <ekarpenkov@apple.com>
Tue, 3 Oct 2017 18:12:15 +0000 (18:12 +0000)
Only assume that IOBSDNameMatching and friends increment a reference counter
if their return type is a CFMutableDictionaryRef.

Differential Revision: https://reviews.llvm.org/D38487

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@314820 91177308-0d34-0410-b5e6-96231b3b80d8

lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp
test/Analysis/retain-release.mm

index 165bc049938879a85ae3ec87f84127c16f6b2752..7212d296a1227e4796c338dbf4a93a53a71323aa 100644 (file)
@@ -1062,6 +1062,7 @@ RetainSummaryManager::getFunctionSummary(const FunctionDecl *FD) {
 
     // Inspect the result type.
     QualType RetTy = FT->getReturnType();
+    StringRef RetTyName = RetTy.getAsString();
 
     // FIXME: This should all be refactored into a chain of "summary lookup"
     //  filters.
@@ -1081,12 +1082,14 @@ RetainSummaryManager::getFunctionSummary(const FunctionDecl *FD) {
       AllowAnnotations = false;
     } else if (FName == "CFPlugInInstanceCreate") {
       S = getPersistentSummary(RetEffect::MakeNoRet());
-    } else if (FName == "IOBSDNameMatching" ||
+    } else if (FName == "IORegistryEntrySearchCFProperty"
+        || (RetTyName == "CFMutableDictionaryRef" && (
+               FName == "IOBSDNameMatching" ||
                FName == "IOServiceMatching" ||
                FName == "IOServiceNameMatching" ||
-               FName == "IORegistryEntrySearchCFProperty" ||
                FName == "IORegistryEntryIDMatching" ||
-               FName == "IOOpenFirmwarePathMatching") {
+               FName == "IOOpenFirmwarePathMatching"
+            ))) {
       // Part of <rdar://problem/6961230>. (IOKit)
       // This should be addressed using a API table.
       S = getPersistentSummary(RetEffect::MakeOwned(RetEffect::CF),
index c694fd33c59602644bc053d1625a8f0f2c5e389b..ac83c1a48e3697f9e3229d3980dded791c373f16 100644 (file)
@@ -463,3 +463,10 @@ void       radar13722286::PrepareBitmap() {
 
 // rdar://34210609
 void _() { _(); }; // no-warning
+
+// Do not assume that IOBSDNameMatching increments a reference counter,
+// unless return type is CFMutableDictionaryRef.
+void* IOBSDNameMatching();
+void rdar33832412() {
+  void* x = IOBSDNameMatching(); // no-warning
+}