1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #include "NoNewThreadsChecker.h"
6 #include "CustomMatchers.h"
8 void NoNewThreadsChecker::registerMatchers(MatchFinder
*AstMatcher
) {
9 // The checker looks for:
10 // -Instances of NS_NewNamedThread that aren't in allowed files
11 // -Instances of NS_NewNamedThread that use names that aren't recognized
12 AstMatcher
->addMatcher(
13 callExpr(allOf(isFirstParty(),
14 callee(functionDecl(hasName("NS_NewNamedThread"))),
15 unless(isInAllowlistForThreads())))
20 void NoNewThreadsChecker::check(const MatchFinder::MatchResult
&Result
) {
21 const CallExpr
*FuncCall
= Result
.Nodes
.getNodeAs
<CallExpr
>("funcCall");
24 diag(FuncCall
->getBeginLoc(),
25 "Thread name not recognized. Please use the background thread pool.",
27 << FuncCall
->getDirectCallee()->getName();
29 FuncCall
->getBeginLoc(),
30 "NS_NewNamedThread has been deprecated in favor of background "
31 "task dispatch via NS_DispatchBackgroundTask and "
32 "NS_CreateBackgroundTaskQueue. If you must create a new ad-hoc thread, "
33 "have your thread name added to ThreadAllows.txt.",