Backed out changeset 106a8fb08a87 (bug 1641389) for causing bc failures on browser_pe...
[gecko.git] / build / clang-plugin / NoNewThreadsChecker.cpp
blob90c190f8d17442f9d2774b90300cd532a74eeda1
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())))
16 .bind("funcCall"),
17 this);
20 void NoNewThreadsChecker::check(const MatchFinder::MatchResult &Result) {
21 const CallExpr *FuncCall = Result.Nodes.getNodeAs<CallExpr>("funcCall");
23 if (FuncCall) {
24 diag(FuncCall->getBeginLoc(),
25 "Thread name not recognized. Please use the background thread pool.",
26 DiagnosticIDs::Error)
27 << FuncCall->getDirectCallee()->getName();
28 diag(
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.",
34 DiagnosticIDs::Note);