From: Ted Kremenek Date: Mon, 14 Nov 2011 21:59:21 +0000 (+0000) Subject: [static analyzer] Tweak RetainCountChecker's diagnostics to correctly indicate if... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4c42bb7815e4f6317826767f8c53776ae03b4028;p=clang [static analyzer] Tweak RetainCountChecker's diagnostics to correctly indicate if a message was due to a property access. This can potentially be refactored for other clients, and this is a regression from the refactoring of property acceses. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@144571 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp b/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp index 4969546de2..9537b31290 100644 --- a/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp +++ b/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp @@ -18,6 +18,7 @@ #include "clang/Basic/LangOptions.h" #include "clang/Basic/SourceManager.h" #include "clang/Analysis/DomainSpecific/CocoaConventions.h" +#include "clang/AST/ParentMap.h" #include "clang/StaticAnalyzer/Core/Checker.h" #include "clang/StaticAnalyzer/Core/CheckerManager.h" #include "clang/StaticAnalyzer/Core/BugReporter/BugType.h" @@ -1815,6 +1816,20 @@ static inline bool contains(const SmallVectorImpl& V, return false; } +static bool isPropertyAccess(const Stmt *S, ParentMap &PM) { + unsigned maxDepth = 4; + while (S && maxDepth) { + if (const PseudoObjectExpr *PO = dyn_cast(S)) { + if (!isa(PO->getSyntacticForm())) + return true; + return false; + } + S = PM.getParent(S); + --maxDepth; + } + return false; +} + PathDiagnosticPiece *CFRefReportVisitor::VisitNode(const ExplodedNode *N, const ExplodedNode *PrevN, BugReporterContext &BRC, @@ -1851,10 +1866,11 @@ PathDiagnosticPiece *CFRefReportVisitor::VisitNode(const ExplodedNode *N, else os << "function call"; } - else if (isa(S)) { - os << "Method"; - } else { - os << "Property"; + else { + assert(isa(S)); + // The message expression may have between written directly or as + // a property access. Lazily determine which case we are looking at. + os << (isPropertyAccess(S, N->getParentMap()) ? "Property" : "Method"); } if (CurrV.getObjKind() == RetEffect::CF) { diff --git a/test/Analysis/retain-release-path-notes.m b/test/Analysis/retain-release-path-notes.m index dfe44748e6..f9676d1abd 100644 --- a/test/Analysis/retain-release-path-notes.m +++ b/test/Analysis/retain-release-path-notes.m @@ -3,7 +3,6 @@ // This actually still works after the pseudo-object refactor, it just // uses messages that say 'method' instead of 'property'. Ted wanted // this xfailed and filed as a bug. rdar://problem/10402993 -// XFAIL: * /*** This file is for testing the path-sensitive notes for retain/release errors.