]> granicus.if.org Git - clang/commitdiff
[analyzer] Fix GCDAntipatternChecker to only fire when the semaphore is initialized...
authorGeorge Karpenkov <ekarpenkov@apple.com>
Mon, 16 Jul 2018 20:32:57 +0000 (20:32 +0000)
committerGeorge Karpenkov <ekarpenkov@apple.com>
Mon, 16 Jul 2018 20:32:57 +0000 (20:32 +0000)
Initializing a semaphore with a different constant most likely signals a different intent

rdar://41802552

Differential Revision: https://reviews.llvm.org/D48911

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@337212 91177308-0d34-0410-b5e6-96231b3b80d8

lib/StaticAnalyzer/Checkers/GCDAntipatternChecker.cpp
test/Analysis/gcdantipatternchecker_test.m

index 1b7ea53aeac68d198c364e6244b793d195d6df1a..5cb51b01f044dfa9a954210d11c3f557781dfc23 100644 (file)
@@ -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(
index adc7a52bf53d94e22c568f9bae1f90ff2863be3c..24ffe8975dd9e480460343979c2f79e734d73292 100644 (file)
@@ -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
+}
+