Author: george.karpenkov Date: Mon Jul 16 13:32:57 2018 New Revision: 337212
URL: http://llvm.org/viewvc/llvm-project?rev=337212&view=rev Log: [analyzer] Fix GCDAntipatternChecker to only fire when the semaphore is initialized to zero Initializing a semaphore with a different constant most likely signals a different intent rdar://41802552 Differential Revision: https://reviews.llvm.org/D48911 Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/GCDAntipatternChecker.cpp cfe/trunk/test/Analysis/gcdantipatternchecker_test.m Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/GCDAntipatternChecker.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/GCDAntipatternChecker.cpp?rev=337212&r1=337211&r2=337212&view=diff ============================================================================== --- cfe/trunk/lib/StaticAnalyzer/Checkers/GCDAntipatternChecker.cpp (original) +++ cfe/trunk/lib/StaticAnalyzer/Checkers/GCDAntipatternChecker.cpp Mon Jul 16 13:32:57 2018 @@ -93,7 +93,9 @@ static bool isTest(const Decl *D) { static auto findGCDAntiPatternWithSemaphore() -> decltype(compoundStmt()) { const char *SemaphoreBinding = "semaphore_name"; - auto SemaphoreCreateM = callExpr(callsName("dispatch_semaphore_create")); + auto SemaphoreCreateM = callExpr(allOf( + callsName("dispatch_semaphore_create"), + hasArgument(0, ignoringParenCasts(integerLiteral(equals(0)))))); auto SemaphoreBindingM = anyOf( forEachDescendant( Modified: cfe/trunk/test/Analysis/gcdantipatternchecker_test.m URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/gcdantipatternchecker_test.m?rev=337212&r1=337211&r2=337212&view=diff ============================================================================== --- cfe/trunk/test/Analysis/gcdantipatternchecker_test.m (original) +++ cfe/trunk/test/Analysis/gcdantipatternchecker_test.m Mon Jul 16 13:32:57 2018 @@ -333,3 +333,13 @@ void dispatch_group_and_semaphore_use(My }]; dispatch_semaphore_wait(sema1, 100); // expected-warning{{Waiting on a callback using a semaphore}} } + +void no_warn_on_nonzero_semaphore(MyInterface1 *M) { + dispatch_semaphore_t sema1 = dispatch_semaphore_create(1); + + [M acceptBlock:^{ + dispatch_semaphore_signal(sema1); + }]; + dispatch_semaphore_wait(sema1, 100); // no-warning +} + _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits