summaryrefslogtreecommitdiffstats
path: root/clang
diff options
context:
space:
mode:
authorGeorge Karpenkov <ekarpenkov@apple.com>2018-03-07 02:54:01 +0000
committerGeorge Karpenkov <ekarpenkov@apple.com>2018-03-07 02:54:01 +0000
commit4cbeeb16959e8b1de5237e092a635e2c137d15a1 (patch)
tree07098c0cbe6da873e6848b3f81ed71db9a9a26a3 /clang
parentfdcbcfb0403d092dd5f9e54a8e9a530b785b26af (diff)
downloadbcm5719-llvm-4cbeeb16959e8b1de5237e092a635e2c137d15a1.tar.gz
bcm5719-llvm-4cbeeb16959e8b1de5237e092a635e2c137d15a1.zip
[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
Diffstat (limited to 'clang')
-rw-r--r--clang/lib/StaticAnalyzer/Checkers/GCDAsyncSemaphoreChecker.cpp25
-rw-r--r--clang/test/Analysis/gcdasyncsemaphorechecker_test.m31
2 files changed, 45 insertions, 11 deletions
diff --git a/clang/lib/StaticAnalyzer/Checkers/GCDAsyncSemaphoreChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/GCDAsyncSemaphoreChecker.cpp
index 23ef032bb05..eda7a5fcd17 100644
--- a/clang/lib/StaticAnalyzer/Checkers/GCDAsyncSemaphoreChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/GCDAsyncSemaphoreChecker.cpp
@@ -111,23 +111,26 @@ void GCDAsyncSemaphoreChecker::checkASTCodeBody(const Decl *D,
)
).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 HasBlockAndCallsSignalM = allOf(HasBlockArgumentM, ArgCallsSignalM);
+
+ auto AcceptsBlockM =
+ forEachDescendant(
+ stmt(anyOf(
+ callExpr(HasBlockAndCallsSignalM),
+ objcMessageExpr(HasBlockAndCallsSignalM)
+ )));
- auto FinalM = compoundStmt(
- SemaphoreBindingM,
- SemaphoreWaitM,
- AcceptsBlockM,
- BlockSignallingM);
+ auto FinalM = compoundStmt(SemaphoreBindingM, SemaphoreWaitM, AcceptsBlockM);
MatchFinder F;
Callback CB(BR, AM.getAnalysisDeclContext(D), this);
diff --git a/clang/test/Analysis/gcdasyncsemaphorechecker_test.m b/clang/test/Analysis/gcdasyncsemaphorechecker_test.m
index a82545a3b6a..ff434d3652d 100644
--- a/clang/test/Analysis/gcdasyncsemaphorechecker_test.m
+++ b/clang/test/Analysis/gcdasyncsemaphorechecker_test.m
@@ -177,7 +177,9 @@ void warn_with_cast() {
@interface Test1 : NSObject
-(void)use_method_warn;
+-(void)use_objc_callback_warn;
-(void)testNoWarn;
+-(void)acceptBlock:(block_t)callback;
@end
@implementation Test1
@@ -200,4 +202,33 @@ void warn_with_cast() {
dispatch_semaphore_wait(sema, 100);
}
+-(void)acceptBlock:(block_t) callback {
+ callback();
+}
+
+-(void)use_objc_callback_warn {
+ dispatch_semaphore_t sema = dispatch_semaphore_create(0);
+
+ [self acceptBlock:^{
+ dispatch_semaphore_signal(sema);
+ }];
+ dispatch_semaphore_wait(sema, 100); // expected-warning{{Possible semaphore performance anti-pattern}}
+}
+
+void use_objc_and_c_callback(Test1 *t) {
+ dispatch_semaphore_t sema = dispatch_semaphore_create(0);
+
+ func(^{
+ dispatch_semaphore_signal(sema);
+ });
+ dispatch_semaphore_wait(sema, 100); // expected-warning{{Possible semaphore performance anti-pattern}}
+
+ dispatch_semaphore_t sema1 = dispatch_semaphore_create(0);
+
+ [t acceptBlock:^{
+ dispatch_semaphore_signal(sema1);
+ }];
+ dispatch_semaphore_wait(sema1, 100); // expected-warning{{Possible semaphore performance anti-pattern}}
+}
+
@end
OpenPOWER on IntegriCloud