diff options
-rw-r--r-- | clang/lib/StaticAnalyzer/Checkers/GCDAntipatternChecker.cpp | 4 | ||||
-rw-r--r-- | clang/test/Analysis/gcdantipatternchecker_test.m | 10 |
2 files changed, 13 insertions, 1 deletions
diff --git a/clang/lib/StaticAnalyzer/Checkers/GCDAntipatternChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/GCDAntipatternChecker.cpp index 1b7ea53aeac..5cb51b01f04 100644 --- a/clang/lib/StaticAnalyzer/Checkers/GCDAntipatternChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/GCDAntipatternChecker.cpp @@ -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( diff --git a/clang/test/Analysis/gcdantipatternchecker_test.m b/clang/test/Analysis/gcdantipatternchecker_test.m index adc7a52bf53..24ffe8975dd 100644 --- a/clang/test/Analysis/gcdantipatternchecker_test.m +++ b/clang/test/Analysis/gcdantipatternchecker_test.m @@ -333,3 +333,13 @@ void dispatch_group_and_semaphore_use(MyInterface1 *M) { }]; 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 +} + |