blob: 8578ef48f292792429984499a4dd6e34fd677a37 [file] [log] [blame]
Daniel Jasperd07c8402013-07-29 08:19:24 +00001//===--- tools/extra/clang-tidy/ClangTidyMain.cpp - Clang tidy tool -------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9///
10/// \file This file implements a clang-tidy tool.
11///
12/// This tool uses the Clang Tooling infrastructure, see
13/// http://clang.llvm.org/docs/HowToSetupToolingForLLVM.html
14/// for details on setting it up with LLVM source tree.
15///
16//===----------------------------------------------------------------------===//
17
18#include "../ClangTidy.h"
Manuel Klimek814f9bd2013-11-14 15:49:44 +000019#include "clang/Tooling/CommonOptionsParser.h"
Alexander Kornienkoe9951542014-09-24 18:36:03 +000020#include "llvm/Support/Process.h"
Daniel Jasperd07c8402013-07-29 08:19:24 +000021
22using namespace clang::ast_matchers;
23using namespace clang::driver;
24using namespace clang::tooling;
25using namespace llvm;
26
Alexander Kornienko99c9d6a2014-02-05 13:43:27 +000027static cl::OptionCategory ClangTidyCategory("clang-tidy options");
Daniel Jasperd07c8402013-07-29 08:19:24 +000028
Manuel Klimek814f9bd2013-11-14 15:49:44 +000029static cl::extrahelp CommonHelp(CommonOptionsParser::HelpMessage);
Alexander Kornienkof1d54eb2016-02-08 00:19:29 +000030static cl::extrahelp ClangTidyHelp(R"(
31Configuration files:
32 clang-tidy attempts to read configuration for each source file from a
33 .clang-tidy file located in the closest parent directory of the source
34 file. If any configuration options have a corresponding command-line
35 option, command-line option takes precedence. The effective
36 configuration can be inspected using -dump-config:
37
38 $ clang-tidy -dump-config - --
39 ---
40 Checks: '-*,some-check'
41 WarningsAsErrors: ''
42 HeaderFilterRegex: ''
43 AnalyzeTemporaryDtors: false
44 User: user
45 CheckOptions:
46 - key: some-check.SomeOption
47 value: 'some value'
48 ...
49
50)");
Daniel Jasperd07c8402013-07-29 08:19:24 +000051
Alexander Kornienko7783ea62016-11-08 08:28:19 +000052const char DefaultChecks[] = // Enable these checks by default:
Alexander Kornienko50ab1562014-10-29 18:25:09 +000053 "clang-diagnostic-*," // * compiler diagnostics
Alexander Kornienko7783ea62016-11-08 08:28:19 +000054 "clang-analyzer-*"; // * Static Analyzer checks
Alexander Kornienkodad4acb2014-05-22 16:07:11 +000055
Alexander Kornienkof1d54eb2016-02-08 00:19:29 +000056static cl::opt<std::string> Checks("checks", cl::desc(R"(
57Comma-separated list of globs with optional '-'
58prefix. Globs are processed in order of
59appearance in the list. Globs without '-'
60prefix add checks with matching names to the
61set, globs with the '-' prefix remove checks
62with matching names from the set of enabled
63checks. This option's value is appended to the
64value of the 'Checks' option in .clang-tidy
65file, if any.
66)"),
67 cl::init(""), cl::cat(ClangTidyCategory));
Alexander Kornienkodad4acb2014-05-22 16:07:11 +000068
Alexander Kornienkof1d54eb2016-02-08 00:19:29 +000069static cl::opt<std::string> WarningsAsErrors("warnings-as-errors", cl::desc(R"(
70Upgrades warnings to errors. Same format as
71'-checks'.
72This option's value is appended to the value of
73the 'WarningsAsErrors' option in .clang-tidy
74file, if any.
75)"),
76 cl::init(""),
77 cl::cat(ClangTidyCategory));
Jonathan Roelofsd60388a2016-01-13 17:36:41 +000078
Alexander Kornienkof1d54eb2016-02-08 00:19:29 +000079static cl::opt<std::string> HeaderFilter("header-filter", cl::desc(R"(
80Regular expression matching the names of the
81headers to output diagnostics from. Diagnostics
82from the main file of each translation unit are
83always displayed.
84Can be used together with -line-filter.
85This option overrides the 'HeaderFilter' option
86in .clang-tidy file, if any.
87)"),
88 cl::init(""),
89 cl::cat(ClangTidyCategory));
Alexander Kornienkodad4acb2014-05-22 16:07:11 +000090
Alexander Kornienko37f7abe2014-10-28 22:16:13 +000091static cl::opt<bool>
92 SystemHeaders("system-headers",
Alexander Kornienko5eac3c62014-11-03 14:06:31 +000093 cl::desc("Display the errors from system headers."),
Alexander Kornienko37f7abe2014-10-28 22:16:13 +000094 cl::init(false), cl::cat(ClangTidyCategory));
Mandeep Singh Grang7c7ea7d2016-11-08 07:50:19 +000095static cl::opt<std::string> LineFilter("line-filter", cl::desc(R"(
Alexander Kornienkof1d54eb2016-02-08 00:19:29 +000096List of files with line ranges to filter the
97warnings. Can be used together with
98-header-filter. The format of the list is a
99JSON array of objects:
100 [
101 {"name":"file1.cpp","lines":[[1,3],[5,7]]},
102 {"name":"file2.h"}
103 ]
104)"),
Mandeep Singh Grang7c7ea7d2016-11-08 07:50:19 +0000105 cl::init(""),
106 cl::cat(ClangTidyCategory));
Alexander Kornienkodad4acb2014-05-22 16:07:11 +0000107
Alexander Kornienkof1d54eb2016-02-08 00:19:29 +0000108static cl::opt<bool> Fix("fix", cl::desc(R"(
109Apply suggested fixes. Without -fix-errors
110clang-tidy will bail out if any compilation
111errors were found.
112)"),
113 cl::init(false), cl::cat(ClangTidyCategory));
Alexander Kornienko5eac3c62014-11-03 14:06:31 +0000114
Alexander Kornienkof1d54eb2016-02-08 00:19:29 +0000115static cl::opt<bool> FixErrors("fix-errors", cl::desc(R"(
116Apply suggested fixes even if compilation
117errors were found. If compiler errors have
118attached fix-its, clang-tidy will apply them as
119well.
120)"),
121 cl::init(false), cl::cat(ClangTidyCategory));
Daniel Jasperd07c8402013-07-29 08:19:24 +0000122
Alexander Kornienkof1d54eb2016-02-08 00:19:29 +0000123static cl::opt<bool> ListChecks("list-checks", cl::desc(R"(
124List all enabled checks and exit. Use with
125-checks=* to list all available checks.
126)"),
127 cl::init(false), cl::cat(ClangTidyCategory));
Daniel Jasperd07c8402013-07-29 08:19:24 +0000128
Haojian Wu12e6b8f2016-04-27 09:15:01 +0000129static cl::opt<bool> ExplainConfig("explain-config", cl::desc(R"(
Haojian Wue5555e22016-09-22 14:36:43 +0000130For each enabled check explains, where it is
131enabled, i.e. in clang-tidy binary, command
132line or a specific configuration file.
Haojian Wu12e6b8f2016-04-27 09:15:01 +0000133)"),
134 cl::init(false), cl::cat(ClangTidyCategory));
135
Alexander Kornienkof1d54eb2016-02-08 00:19:29 +0000136static cl::opt<std::string> Config("config", cl::desc(R"(
137Specifies a configuration in YAML/JSON format:
138 -config="{Checks: '*',
139 CheckOptions: [{key: x,
140 value: y}]}"
141When the value is empty, clang-tidy will
142attempt to find a file named .clang-tidy for
143each source file in its parent directories.
144)"),
145 cl::init(""), cl::cat(ClangTidyCategory));
Alexander Kornienkoeff4e922014-09-26 11:42:29 +0000146
Alexander Kornienkof1d54eb2016-02-08 00:19:29 +0000147static cl::opt<bool> DumpConfig("dump-config", cl::desc(R"(
148Dumps configuration in the YAML format to
149stdout. This option can be used along with a
150file name (and '--' if the file is outside of a
151project with configured compilation database).
152The configuration used for this file will be
153printed.
154Use along with -checks=* to include
155configuration of all checks.
156)"),
157 cl::init(false), cl::cat(ClangTidyCategory));
Alexander Kornienkod53d2682014-09-04 14:23:36 +0000158
Alexander Kornienkof1d54eb2016-02-08 00:19:29 +0000159static cl::opt<bool> EnableCheckProfile("enable-check-profile", cl::desc(R"(
160Enable per-check timing profiles, and print a
161report to stderr.
162)"),
163 cl::init(false),
164 cl::cat(ClangTidyCategory));
Samuel Benzaquenaedd9942014-10-23 17:23:20 +0000165
Alexander Kornienkof1d54eb2016-02-08 00:19:29 +0000166static cl::opt<bool> AnalyzeTemporaryDtors("analyze-temporary-dtors",
167 cl::desc(R"(
168Enable temporary destructor-aware analysis in
169clang-analyzer- checks.
170This option overrides the value read from a
171.clang-tidy file.
172)"),
173 cl::init(false),
174 cl::cat(ClangTidyCategory));
Alex McCarthyfec08c72014-04-30 14:09:24 +0000175
Alexander Kornienkof1d54eb2016-02-08 00:19:29 +0000176static cl::opt<std::string> ExportFixes("export-fixes", cl::desc(R"(
177YAML file to store suggested fixes in. The
Kirill Bobyrev405699e2016-08-19 09:36:14 +0000178stored fixes can be applied to the input source
Alexander Kornienkof1d54eb2016-02-08 00:19:29 +0000179code with clang-apply-replacements.
180)"),
181 cl::value_desc("filename"),
182 cl::cat(ClangTidyCategory));
Benjamin Kramerfb98b742014-09-04 10:31:23 +0000183
Alexander Kornienkoc28c32d2014-09-10 11:43:09 +0000184namespace clang {
185namespace tidy {
186
187static void printStats(const ClangTidyStats &Stats) {
Alexander Kornienkodad4acb2014-05-22 16:07:11 +0000188 if (Stats.errorsIgnored()) {
189 llvm::errs() << "Suppressed " << Stats.errorsIgnored() << " warnings (";
Alexander Kornienko5d174542014-05-07 09:06:53 +0000190 StringRef Separator = "";
191 if (Stats.ErrorsIgnoredNonUserCode) {
192 llvm::errs() << Stats.ErrorsIgnoredNonUserCode << " in non-user code";
193 Separator = ", ";
194 }
Alexander Kornienkodad4acb2014-05-22 16:07:11 +0000195 if (Stats.ErrorsIgnoredLineFilter) {
196 llvm::errs() << Separator << Stats.ErrorsIgnoredLineFilter
197 << " due to line filter";
198 Separator = ", ";
199 }
Alexander Kornienko5d174542014-05-07 09:06:53 +0000200 if (Stats.ErrorsIgnoredNOLINT) {
201 llvm::errs() << Separator << Stats.ErrorsIgnoredNOLINT << " NOLINT";
202 Separator = ", ";
203 }
204 if (Stats.ErrorsIgnoredCheckFilter)
205 llvm::errs() << Separator << Stats.ErrorsIgnoredCheckFilter
206 << " with check filters";
207 llvm::errs() << ").\n";
208 if (Stats.ErrorsIgnoredNonUserCode)
Aaron Ballman5a4892b2015-07-27 13:41:30 +0000209 llvm::errs() << "Use -header-filter=.* to display errors from all "
Alexander Kornienkof1d54eb2016-02-08 00:19:29 +0000210 "non-system headers. Use -system-headers to display "
211 "errors from system headers as well.\n";
Alexander Kornienko5d174542014-05-07 09:06:53 +0000212 }
213}
214
Samuel Benzaquenaedd9942014-10-23 17:23:20 +0000215static void printProfileData(const ProfileData &Profile,
216 llvm::raw_ostream &OS) {
217 // Time is first to allow for sorting by it.
218 std::vector<std::pair<llvm::TimeRecord, StringRef>> Timers;
219 TimeRecord Total;
220
Mandeep Singh Grang7c7ea7d2016-11-08 07:50:19 +0000221 for (const auto &P : Profile.Records) {
Samuel Benzaquenaedd9942014-10-23 17:23:20 +0000222 Timers.emplace_back(P.getValue(), P.getKey());
223 Total += P.getValue();
224 }
225
226 std::sort(Timers.begin(), Timers.end());
227
228 std::string Line = "===" + std::string(73, '-') + "===\n";
229 OS << Line;
230
231 if (Total.getUserTime())
232 OS << " ---User Time---";
233 if (Total.getSystemTime())
234 OS << " --System Time--";
235 if (Total.getProcessTime())
236 OS << " --User+System--";
237 OS << " ---Wall Time---";
238 if (Total.getMemUsed())
239 OS << " ---Mem---";
240 OS << " --- Name ---\n";
241
242 // Loop through all of the timing data, printing it out.
243 for (auto I = Timers.rbegin(), E = Timers.rend(); I != E; ++I) {
244 I->first.print(Total, OS);
245 OS << I->second << '\n';
246 }
247
248 Total.print(Total, OS);
249 OS << "Total\n";
250 OS << Line << "\n";
251 OS.flush();
252}
253
Benjamin Kramere7103712015-03-23 12:49:15 +0000254static std::unique_ptr<ClangTidyOptionsProvider> createOptionsProvider() {
Alexander Kornienkoc28c32d2014-09-10 11:43:09 +0000255 ClangTidyGlobalOptions GlobalOptions;
256 if (std::error_code Err = parseLineFilter(LineFilter, GlobalOptions)) {
Alexander Kornienkodad4acb2014-05-22 16:07:11 +0000257 llvm::errs() << "Invalid LineFilter: " << Err.message() << "\n\nUsage:\n";
258 llvm::cl::PrintHelpMessage(/*Hidden=*/false, /*Categorized=*/true);
Alexander Kornienkoeff4e922014-09-26 11:42:29 +0000259 return nullptr;
Alexander Kornienkodad4acb2014-05-22 16:07:11 +0000260 }
Alexander Kornienko33a9bcc2014-04-29 15:20:10 +0000261
Alexander Kornienkoe9951542014-09-24 18:36:03 +0000262 ClangTidyOptions DefaultOptions;
263 DefaultOptions.Checks = DefaultChecks;
Jonathan Roelofsd60388a2016-01-13 17:36:41 +0000264 DefaultOptions.WarningsAsErrors = "";
Alexander Kornienkoe9951542014-09-24 18:36:03 +0000265 DefaultOptions.HeaderFilterRegex = HeaderFilter;
Alexander Kornienko37f7abe2014-10-28 22:16:13 +0000266 DefaultOptions.SystemHeaders = SystemHeaders;
Alexander Kornienkoe9951542014-09-24 18:36:03 +0000267 DefaultOptions.AnalyzeTemporaryDtors = AnalyzeTemporaryDtors;
268 DefaultOptions.User = llvm::sys::Process::GetEnv("USER");
269 // USERNAME is used on Windows.
270 if (!DefaultOptions.User)
271 DefaultOptions.User = llvm::sys::Process::GetEnv("USERNAME");
Alexander Kornienkoa4695222014-06-05 13:31:45 +0000272
Alexander Kornienkoc28c32d2014-09-10 11:43:09 +0000273 ClangTidyOptions OverrideOptions;
Alexander Kornienkod53d2682014-09-04 14:23:36 +0000274 if (Checks.getNumOccurrences() > 0)
275 OverrideOptions.Checks = Checks;
Jonathan Roelofsd60388a2016-01-13 17:36:41 +0000276 if (WarningsAsErrors.getNumOccurrences() > 0)
277 OverrideOptions.WarningsAsErrors = WarningsAsErrors;
Alexander Kornienkod53d2682014-09-04 14:23:36 +0000278 if (HeaderFilter.getNumOccurrences() > 0)
279 OverrideOptions.HeaderFilterRegex = HeaderFilter;
Alexander Kornienko37f7abe2014-10-28 22:16:13 +0000280 if (SystemHeaders.getNumOccurrences() > 0)
281 OverrideOptions.SystemHeaders = SystemHeaders;
Alexander Kornienkod53d2682014-09-04 14:23:36 +0000282 if (AnalyzeTemporaryDtors.getNumOccurrences() > 0)
283 OverrideOptions.AnalyzeTemporaryDtors = AnalyzeTemporaryDtors;
284
Alexander Kornienkoeff4e922014-09-26 11:42:29 +0000285 if (!Config.empty()) {
286 if (llvm::ErrorOr<ClangTidyOptions> ParsedConfig =
287 parseConfiguration(Config)) {
Haojian Wu12e6b8f2016-04-27 09:15:01 +0000288 return llvm::make_unique<ConfigOptionsProvider>(
289 GlobalOptions,
290 ClangTidyOptions::getDefaults().mergeWith(DefaultOptions),
291 *ParsedConfig, OverrideOptions);
Alexander Kornienkoeff4e922014-09-26 11:42:29 +0000292 } else {
293 llvm::errs() << "Error: invalid configuration specified.\n"
294 << ParsedConfig.getError().message() << "\n";
295 return nullptr;
296 }
297 }
298 return llvm::make_unique<FileOptionsProvider>(GlobalOptions, DefaultOptions,
299 OverrideOptions);
300}
301
Benjamin Kramere7103712015-03-23 12:49:15 +0000302static int clangTidyMain(int argc, const char **argv) {
Alexander Kornienko65eccb42015-08-17 10:03:27 +0000303 CommonOptionsParser OptionsParser(argc, argv, ClangTidyCategory,
304 cl::ZeroOrMore);
Alexander Kornienkoeff4e922014-09-26 11:42:29 +0000305
306 auto OptionsProvider = createOptionsProvider();
307 if (!OptionsProvider)
308 return 1;
Alexander Kornienkod53d2682014-09-04 14:23:36 +0000309
Alexander Kornienko65eccb42015-08-17 10:03:27 +0000310 StringRef FileName("dummy");
311 auto PathList = OptionsParser.getSourcePathList();
312 if (!PathList.empty()) {
Alexander Kornienkoe0c900e2015-08-17 11:27:11 +0000313 FileName = PathList.front();
Alexander Kornienko65eccb42015-08-17 10:03:27 +0000314 }
Haojian Wud1218752016-07-11 07:47:04 +0000315
316 SmallString<256> FilePath(FileName);
317 if (std::error_code EC = llvm::sys::fs::make_absolute(FilePath)) {
318 llvm::errs() << "Can't make absolute path from " << FileName << ": "
319 << EC.message() << "\n";
320 }
321 ClangTidyOptions EffectiveOptions = OptionsProvider->getOptions(FilePath);
Alexander Kornienkoc28c32d2014-09-10 11:43:09 +0000322 std::vector<std::string> EnabledChecks = getCheckNames(EffectiveOptions);
Alexander Kornienkofbf92582014-06-02 20:32:06 +0000323
Haojian Wu12e6b8f2016-04-27 09:15:01 +0000324 if (ExplainConfig) {
Mandeep Singh Grang7c7ea7d2016-11-08 07:50:19 +0000325 // FIXME: Show other ClangTidyOptions' fields, like ExtraArg.
Haojian Wu12e6b8f2016-04-27 09:15:01 +0000326 std::vector<clang::tidy::ClangTidyOptionsProvider::OptionsSource>
Haojian Wud1218752016-07-11 07:47:04 +0000327 RawOptions = OptionsProvider->getRawOptions(FilePath);
Haojian Wu12e6b8f2016-04-27 09:15:01 +0000328 for (const std::string &Check : EnabledChecks) {
329 for (auto It = RawOptions.rbegin(); It != RawOptions.rend(); ++It) {
330 if (It->first.Checks && GlobList(*It->first.Checks).contains(Check)) {
331 llvm::outs() << "'" << Check << "' is enabled in the " << It->second
332 << ".\n";
333 break;
334 }
335 }
336 }
337 return 0;
338 }
339
Alexander Kornienkofb9e92b2013-12-19 19:57:05 +0000340 if (ListChecks) {
Alexander Kornienko493db092016-04-27 11:45:14 +0000341 if (EnabledChecks.empty()) {
342 llvm::errs() << "No checks enabled.\n";
343 return 1;
344 }
Alexander Kornienkofb9e92b2013-12-19 19:57:05 +0000345 llvm::outs() << "Enabled checks:";
Benjamin Kramer51a9cc92016-06-15 15:46:10 +0000346 for (const auto &CheckName : EnabledChecks)
Alexander Kornienko16ac6ce2014-03-05 13:14:32 +0000347 llvm::outs() << "\n " << CheckName;
Alexander Kornienkofb9e92b2013-12-19 19:57:05 +0000348 llvm::outs() << "\n\n";
349 return 0;
350 }
351
Alexander Kornienkod53d2682014-09-04 14:23:36 +0000352 if (DumpConfig) {
Alexander Kornienko6e0cbc82014-09-12 08:53:36 +0000353 EffectiveOptions.CheckOptions = getCheckOptions(EffectiveOptions);
Alexander Kornienko65eccb42015-08-17 10:03:27 +0000354 llvm::outs() << configurationAsText(
355 ClangTidyOptions::getDefaults().mergeWith(
356 EffectiveOptions))
Alexander Kornienkod53d2682014-09-04 14:23:36 +0000357 << "\n";
358 return 0;
359 }
360
Alexander Kornienkofbf92582014-06-02 20:32:06 +0000361 if (EnabledChecks.empty()) {
362 llvm::errs() << "Error: no checks enabled.\n";
363 llvm::cl::PrintHelpMessage(/*Hidden=*/false, /*Categorized=*/true);
364 return 1;
365 }
366
Alexander Kornienko65eccb42015-08-17 10:03:27 +0000367 if (PathList.empty()) {
368 llvm::errs() << "Error: no input files specified.\n";
369 llvm::cl::PrintHelpMessage(/*Hidden=*/false, /*Categorized=*/true);
370 return 1;
371 }
372
Samuel Benzaquenaedd9942014-10-23 17:23:20 +0000373 ProfileData Profile;
374
Alexander Kornienkoc28c32d2014-09-10 11:43:09 +0000375 std::vector<ClangTidyError> Errors;
376 ClangTidyStats Stats =
377 runClangTidy(std::move(OptionsProvider), OptionsParser.getCompilations(),
Mandeep Singh Grang7c7ea7d2016-11-08 07:50:19 +0000378 PathList, &Errors, EnableCheckProfile ? &Profile : nullptr);
Alexander Kornienko5eac3c62014-11-03 14:06:31 +0000379 bool FoundErrors =
380 std::find_if(Errors.begin(), Errors.end(), [](const ClangTidyError &E) {
381 return E.DiagLevel == ClangTidyError::Error;
382 }) != Errors.end();
383
384 const bool DisableFixes = Fix && FoundErrors && !FixErrors;
385
Jonathan Roelofsd60388a2016-01-13 17:36:41 +0000386 unsigned WErrorCount = 0;
387
Alexander Kornienko5eac3c62014-11-03 14:06:31 +0000388 // -fix-errors implies -fix.
Jonathan Roelofsd60388a2016-01-13 17:36:41 +0000389 handleErrors(Errors, (FixErrors || Fix) && !DisableFixes, WErrorCount);
Daniel Jasperd07c8402013-07-29 08:19:24 +0000390
Alexander Kornienko4153da22014-09-04 15:19:49 +0000391 if (!ExportFixes.empty() && !Errors.empty()) {
Benjamin Kramerfb98b742014-09-04 10:31:23 +0000392 std::error_code EC;
393 llvm::raw_fd_ostream OS(ExportFixes, EC, llvm::sys::fs::F_None);
394 if (EC) {
395 llvm::errs() << "Error opening output file: " << EC.message() << '\n';
396 return 1;
397 }
Alexander Kornienkoc28c32d2014-09-10 11:43:09 +0000398 exportReplacements(Errors, OS);
Benjamin Kramerfb98b742014-09-04 10:31:23 +0000399 }
400
Alexander Kornienko5d174542014-05-07 09:06:53 +0000401 printStats(Stats);
Alexander Kornienko5eac3c62014-11-03 14:06:31 +0000402 if (DisableFixes)
Alexander Kornienkob0a9b702014-12-09 15:02:17 +0000403 llvm::errs()
404 << "Found compiler errors, but -fix-errors was not specified.\n"
405 "Fixes have NOT been applied.\n\n";
Alexander Kornienko5eac3c62014-11-03 14:06:31 +0000406
Samuel Benzaquenaedd9942014-10-23 17:23:20 +0000407 if (EnableCheckProfile)
408 printProfileData(Profile, llvm::errs());
409
Jonathan Roelofsd60388a2016-01-13 17:36:41 +0000410 if (WErrorCount) {
411 StringRef Plural = WErrorCount == 1 ? "" : "s";
412 llvm::errs() << WErrorCount << " warning" << Plural << " treated as error"
413 << Plural << "\n";
414 return WErrorCount;
415 }
416
Daniel Jasperd07c8402013-07-29 08:19:24 +0000417 return 0;
418}
Daniel Jasper89bbab02013-08-04 15:56:30 +0000419
Aaron Ballmanea2f90c2015-10-02 13:27:19 +0000420// This anchor is used to force the linker to link the CERTModule.
421extern volatile int CERTModuleAnchorSource;
422static int LLVM_ATTRIBUTE_UNUSED CERTModuleAnchorDestination =
423 CERTModuleAnchorSource;
424
Piotr Padlewski5625f652016-04-29 17:58:29 +0000425// This anchor is used to force the linker to link the BoostModule.
426extern volatile int BoostModuleAnchorSource;
427static int LLVM_ATTRIBUTE_UNUSED BoostModuleAnchorDestination =
428 BoostModuleAnchorSource;
429
Daniel Jasper89bbab02013-08-04 15:56:30 +0000430// This anchor is used to force the linker to link the LLVMModule.
431extern volatile int LLVMModuleAnchorSource;
Alexander Kornienkoe1292f82015-08-19 16:54:51 +0000432static int LLVM_ATTRIBUTE_UNUSED LLVMModuleAnchorDestination =
433 LLVMModuleAnchorSource;
Daniel Jasper89bbab02013-08-04 15:56:30 +0000434
Aaron Ballmanaaa40802015-10-06 13:31:00 +0000435// This anchor is used to force the linker to link the CppCoreGuidelinesModule.
436extern volatile int CppCoreGuidelinesModuleAnchorSource;
437static int LLVM_ATTRIBUTE_UNUSED CppCoreGuidelinesModuleAnchorDestination =
438 CppCoreGuidelinesModuleAnchorSource;
439
Daniel Jasper89bbab02013-08-04 15:56:30 +0000440// This anchor is used to force the linker to link the GoogleModule.
441extern volatile int GoogleModuleAnchorSource;
Alexander Kornienkoe1292f82015-08-19 16:54:51 +0000442static int LLVM_ATTRIBUTE_UNUSED GoogleModuleAnchorDestination =
443 GoogleModuleAnchorSource;
Daniel Jasper89bbab02013-08-04 15:56:30 +0000444
Alexander Kornienko16ac6ce2014-03-05 13:14:32 +0000445// This anchor is used to force the linker to link the MiscModule.
446extern volatile int MiscModuleAnchorSource;
Alexander Kornienkoe1292f82015-08-19 16:54:51 +0000447static int LLVM_ATTRIBUTE_UNUSED MiscModuleAnchorDestination =
448 MiscModuleAnchorSource;
Alexander Kornienko16ac6ce2014-03-05 13:14:32 +0000449
Alexander Kornienkofc650862015-08-14 13:17:11 +0000450// This anchor is used to force the linker to link the ModernizeModule.
451extern volatile int ModernizeModuleAnchorSource;
Alexander Kornienkoe1292f82015-08-19 16:54:51 +0000452static int LLVM_ATTRIBUTE_UNUSED ModernizeModuleAnchorDestination =
453 ModernizeModuleAnchorSource;
Alexander Kornienkofc650862015-08-14 13:17:11 +0000454
Alexander Kornienko5e0a50c2016-08-02 20:29:35 +0000455// This anchor is used to force the linker to link the MPIModule.
456extern volatile int MPIModuleAnchorSource;
457static int LLVM_ATTRIBUTE_UNUSED MPIModuleAnchorDestination =
Mandeep Singh Grang7c7ea7d2016-11-08 07:50:19 +0000458 MPIModuleAnchorSource;
Alexander Kornienko5e0a50c2016-08-02 20:29:35 +0000459
Alexander Kornienkob959f4c2015-12-30 10:24:40 +0000460// This anchor is used to force the linker to link the PerformanceModule.
461extern volatile int PerformanceModuleAnchorSource;
462static int LLVM_ATTRIBUTE_UNUSED PerformanceModuleAnchorDestination =
463 PerformanceModuleAnchorSource;
464
Alexander Kornienko2192a8e2014-10-26 01:41:14 +0000465// This anchor is used to force the linker to link the ReadabilityModule.
466extern volatile int ReadabilityModuleAnchorSource;
Alexander Kornienkoe1292f82015-08-19 16:54:51 +0000467static int LLVM_ATTRIBUTE_UNUSED ReadabilityModuleAnchorDestination =
468 ReadabilityModuleAnchorSource;
Alexander Kornienko2192a8e2014-10-26 01:41:14 +0000469
Daniel Jasper89bbab02013-08-04 15:56:30 +0000470} // namespace tidy
471} // namespace clang
Alexander Kornienkoc28c32d2014-09-10 11:43:09 +0000472
473int main(int argc, const char **argv) {
474 return clang::tidy::clangTidyMain(argc, argv);
475}