From a171bb0ee4a63cd1e6bdffc81a71bca914a929a9 Mon Sep 17 00:00:00 2001 From: George Karpenkov Date: Tue, 3 Oct 2017 23:15:35 +0000 Subject: [PATCH] [Analyzer] Re-apply r314820 with a fix for StringRef lifetime. Fixes the test failure: temporary is now bound to std::string, tests fully pass on Linux. This reverts commit b36ee0924038e1d95ea74230c62d46e05f80587e. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@314859 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp | 9 ++++++--- test/Analysis/retain-release.mm | 7 +++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp b/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp index 165bc04993..09a64899df 100644 --- a/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp +++ b/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp @@ -1062,6 +1062,7 @@ RetainSummaryManager::getFunctionSummary(const FunctionDecl *FD) { // Inspect the result type. QualType RetTy = FT->getReturnType(); + std::string 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 . (IOKit) // This should be addressed using a API table. S = getPersistentSummary(RetEffect::MakeOwned(RetEffect::CF), diff --git a/test/Analysis/retain-release.mm b/test/Analysis/retain-release.mm index c694fd33c5..ac83c1a48e 100644 --- a/test/Analysis/retain-release.mm +++ b/test/Analysis/retain-release.mm @@ -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 +} -- 2.40.0