From: George Karpenkov Date: Tue, 13 Mar 2018 17:27:01 +0000 (+0000) Subject: [analyzer] Fix the matcher for GCDAntipattern to look for "signal" call in all parameters X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d649f2fa4e7c74f8467195b5b6dbcf0925a64819;p=clang [analyzer] Fix the matcher for GCDAntipattern to look for "signal" call in all parameters rdar://38405904 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@327426 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/StaticAnalyzer/Checkers/GCDAntipatternChecker.cpp b/lib/StaticAnalyzer/Checkers/GCDAntipatternChecker.cpp index 51a3fc1938..bb1bd85ce0 100644 --- a/lib/StaticAnalyzer/Checkers/GCDAntipatternChecker.cpp +++ b/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/test/Analysis/gcdantipatternchecker_test.m b/test/Analysis/gcdantipatternchecker_test.m index 19f446787c..42e54dbfdc 100644 --- a/test/Analysis/gcdantipatternchecker_test.m +++ b/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);