Deleted Added
full compact
1//===- GCDAntipatternChecker.cpp ---------------------------------*- C++ -*-==//
2//
3// The LLVM Compiler Infrastructure
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
7//===----------------------------------------------------------------------===//
8//
9// This file defines GCDAntipatternChecker which checks against a common
10// antipattern when synchronous API is emulated from asynchronous callbacks
11// using a semaphore:
12//
13// dispatch_semaphore_t sema = dispatch_semaphore_create(0);
14//

--- 176 unchanged lines hidden (view full) ---

191 OS << "Waiting on a callback using a " << Type << " creates useless threads "
192 << "and is subject to priority inversion; consider "
193 << "using a synchronous API or changing the caller to be asynchronous";
194
195 BR.EmitBasicReport(
196 ADC->getDecl(),
197 Checker,
198 /*Name=*/"GCD performance anti-pattern",
200 /*Category=*/"Performance",
199 /*BugCategory=*/"Performance",
200 OS.str(),
201 PathDiagnosticLocation::createBegin(SW, BR.getSourceManager(), ADC),
202 SW->getSourceRange());
203}
204
205void GCDAntipatternChecker::checkASTCodeBody(const Decl *D,
206 AnalysisManager &AM,
207 BugReporter &BR) const {

--- 8 unchanged lines hidden (view full) ---

216 emitDiagnostics(Match, "semaphore", BR, ADC, this);
217
218 auto GroupMatcherM = findGCDAntiPatternWithGroup();
219 Matches = match(GroupMatcherM, *D->getBody(), AM.getASTContext());
220 for (BoundNodes Match : Matches)
221 emitDiagnostics(Match, "group", BR, ADC, this);
222}
223
225}
224} // end of anonymous namespace
225
226void ento::registerGCDAntipattern(CheckerManager &Mgr) {
227 Mgr.registerChecker<GCDAntipatternChecker>();
228}
229
230bool ento::shouldRegisterGCDAntipattern(const LangOptions &LO) {
231 return true;
232}