diff options
| -rw-r--r-- | clang/lib/StaticAnalyzer/Checkers/GCDAntipatternChecker.cpp | 4 | ||||
| -rw-r--r-- | clang/test/Analysis/gcdantipatternchecker_test.m | 15 |
2 files changed, 17 insertions, 2 deletions
diff --git a/clang/lib/StaticAnalyzer/Checkers/GCDAntipatternChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/GCDAntipatternChecker.cpp index 51a3fc19386..bb1bd85ce0b 100644 --- a/clang/lib/StaticAnalyzer/Checkers/GCDAntipatternChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/GCDAntipatternChecker.cpp @@ -121,11 +121,11 @@ void GCDAntipatternChecker::checkASTCodeBody(const Decl *D, hasCanonicalType(blockPointerType()) )); - auto ArgCallsSignalM = hasArgument(0, hasDescendant(callExpr( + auto ArgCallsSignalM = hasAnyArgument(stmt(hasDescendant(callExpr( allOf( callsName("dispatch_semaphore_signal"), equalsBoundArgDecl(0, SemaphoreBinding) - )))); + ))))); auto HasBlockAndCallsSignalM = allOf(HasBlockArgumentM, ArgCallsSignalM); diff --git a/clang/test/Analysis/gcdantipatternchecker_test.m b/clang/test/Analysis/gcdantipatternchecker_test.m index 19f446787c0..42e54dbfdc2 100644 --- a/clang/test/Analysis/gcdantipatternchecker_test.m +++ b/clang/test/Analysis/gcdantipatternchecker_test.m @@ -177,9 +177,11 @@ void warn_with_cast() { @interface MyInterface1 : NSObject -(void)use_method_warn; +-(void) pass_block_as_second_param_warn; -(void)use_objc_callback_warn; -(void)testNoWarn; -(void)acceptBlock:(block_t)callback; +-(void)flag:(int)flag acceptBlock:(block_t)callback; @end @implementation MyInterface1 @@ -193,6 +195,15 @@ void warn_with_cast() { dispatch_semaphore_wait(sema, 100); // expected-warning{{Waiting on a semaphore with Grand Central Dispatch creates useless threads and is subject to priority inversion}} } +-(void) pass_block_as_second_param_warn { + dispatch_semaphore_t sema = dispatch_semaphore_create(0); + + [self flag:1 acceptBlock:^{ + dispatch_semaphore_signal(sema); + }]; + dispatch_semaphore_wait(sema, 100); // expected-warning{{Waiting on a semaphore with Grand Central Dispatch creates useless threads and is subject to priority inversion}} +} + -(void)testNoWarn { dispatch_semaphore_t sema = dispatch_semaphore_create(0); @@ -206,6 +217,10 @@ void warn_with_cast() { callback(); } +-(void)flag:(int)flag acceptBlock:(block_t)callback { + callback(); +} + -(void)use_objc_callback_warn { dispatch_semaphore_t sema = dispatch_semaphore_create(0); |

