[analyzer] Fix the checker for the performance anti-pattern to accept messages
send to ObjC objects.
Differential Revision: https://reviews.llvm.org/D44170
llvm-svn: 326868
diff --git a/clang/lib/StaticAnalyzer/Checkers/GCDAsyncSemaphoreChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/GCDAsyncSemaphoreChecker.cpp
index 23ef032..eda7a5f 100644
--- a/clang/lib/StaticAnalyzer/Checkers/GCDAsyncSemaphoreChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/GCDAsyncSemaphoreChecker.cpp
@@ -111,23 +111,26 @@
)
).bind(WarningBinding));
- auto AcceptsBlockM =
- forEachDescendant(callExpr(hasAnyArgument(hasType(
+ auto HasBlockArgumentM = hasAnyArgument(hasType(
hasCanonicalType(blockPointerType())
- ))));
+ ));
- auto BlockSignallingM =
- forEachDescendant(callExpr(hasAnyArgument(hasDescendant(callExpr(
+ auto ArgCallsSignalM = hasArgument(0, hasDescendant(callExpr(
allOf(
callsName("dispatch_semaphore_signal"),
equalsBoundArgDecl(0, SemaphoreBinding)
- ))))));
+ ))));
- auto FinalM = compoundStmt(
- SemaphoreBindingM,
- SemaphoreWaitM,
- AcceptsBlockM,
- BlockSignallingM);
+ auto HasBlockAndCallsSignalM = allOf(HasBlockArgumentM, ArgCallsSignalM);
+
+ auto AcceptsBlockM =
+ forEachDescendant(
+ stmt(anyOf(
+ callExpr(HasBlockAndCallsSignalM),
+ objcMessageExpr(HasBlockAndCallsSignalM)
+ )));
+
+ auto FinalM = compoundStmt(SemaphoreBindingM, SemaphoreWaitM, AcceptsBlockM);
MatchFinder F;
Callback CB(BR, AM.getAnalysisDeclContext(D), this);