blob: fd53c4e6ee24f4b66737ddb9910a9c9803ddc320 [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
Jonas Devlieghere73191842016-11-30 18:06:42 +000052const char DefaultChecks[] = // Enable these checks by default:
53 "clang-diagnostic-*," // * compiler diagnostics
54 "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
Jonas Devlieghere73191842016-11-30 18:06:42 +0000123static cl::opt<std::string> FormatStyle("style", cl::desc(R"(
124Fallback style for reformatting after inserting fixes
125if there is no clang-format config file found.
126)"),
127 cl::init("llvm"),
128 cl::cat(ClangTidyCategory));
129
Alexander Kornienkof1d54eb2016-02-08 00:19:29 +0000130static cl::opt<bool> ListChecks("list-checks", cl::desc(R"(
131List all enabled checks and exit. Use with
132-checks=* to list all available checks.
133)"),
134 cl::init(false), cl::cat(ClangTidyCategory));
Daniel Jasperd07c8402013-07-29 08:19:24 +0000135
Haojian Wu12e6b8f2016-04-27 09:15:01 +0000136static cl::opt<bool> ExplainConfig("explain-config", cl::desc(R"(
Haojian Wue5555e22016-09-22 14:36:43 +0000137For each enabled check explains, where it is
138enabled, i.e. in clang-tidy binary, command
139line or a specific configuration file.
Haojian Wu12e6b8f2016-04-27 09:15:01 +0000140)"),
141 cl::init(false), cl::cat(ClangTidyCategory));
142
Alexander Kornienkof1d54eb2016-02-08 00:19:29 +0000143static cl::opt<std::string> Config("config", cl::desc(R"(
144Specifies a configuration in YAML/JSON format:
145 -config="{Checks: '*',
146 CheckOptions: [{key: x,
147 value: y}]}"
148When the value is empty, clang-tidy will
149attempt to find a file named .clang-tidy for
150each source file in its parent directories.
151)"),
152 cl::init(""), cl::cat(ClangTidyCategory));
Alexander Kornienkoeff4e922014-09-26 11:42:29 +0000153
Alexander Kornienkof1d54eb2016-02-08 00:19:29 +0000154static cl::opt<bool> DumpConfig("dump-config", cl::desc(R"(
155Dumps configuration in the YAML format to
156stdout. This option can be used along with a
157file name (and '--' if the file is outside of a
158project with configured compilation database).
159The configuration used for this file will be
160printed.
161Use along with -checks=* to include
162configuration of all checks.
163)"),
164 cl::init(false), cl::cat(ClangTidyCategory));
Alexander Kornienkod53d2682014-09-04 14:23:36 +0000165
Alexander Kornienkof1d54eb2016-02-08 00:19:29 +0000166static cl::opt<bool> EnableCheckProfile("enable-check-profile", cl::desc(R"(
167Enable per-check timing profiles, and print a
168report to stderr.
169)"),
170 cl::init(false),
171 cl::cat(ClangTidyCategory));
Samuel Benzaquenaedd9942014-10-23 17:23:20 +0000172
Alexander Kornienkof1d54eb2016-02-08 00:19:29 +0000173static cl::opt<bool> AnalyzeTemporaryDtors("analyze-temporary-dtors",
174 cl::desc(R"(
175Enable temporary destructor-aware analysis in
176clang-analyzer- checks.
177This option overrides the value read from a
178.clang-tidy file.
179)"),
180 cl::init(false),
181 cl::cat(ClangTidyCategory));
Alex McCarthyfec08c72014-04-30 14:09:24 +0000182
Alexander Kornienkof1d54eb2016-02-08 00:19:29 +0000183static cl::opt<std::string> ExportFixes("export-fixes", cl::desc(R"(
184YAML file to store suggested fixes in. The
Kirill Bobyrev405699e2016-08-19 09:36:14 +0000185stored fixes can be applied to the input source
Alexander Kornienkof1d54eb2016-02-08 00:19:29 +0000186code with clang-apply-replacements.
187)"),
188 cl::value_desc("filename"),
189 cl::cat(ClangTidyCategory));
Benjamin Kramerfb98b742014-09-04 10:31:23 +0000190
Alexander Kornienkoc28c32d2014-09-10 11:43:09 +0000191namespace clang {
192namespace tidy {
193
194static void printStats(const ClangTidyStats &Stats) {
Alexander Kornienkodad4acb2014-05-22 16:07:11 +0000195 if (Stats.errorsIgnored()) {
196 llvm::errs() << "Suppressed " << Stats.errorsIgnored() << " warnings (";
Alexander Kornienko5d174542014-05-07 09:06:53 +0000197 StringRef Separator = "";
198 if (Stats.ErrorsIgnoredNonUserCode) {
199 llvm::errs() << Stats.ErrorsIgnoredNonUserCode << " in non-user code";
200 Separator = ", ";
201 }
Alexander Kornienkodad4acb2014-05-22 16:07:11 +0000202 if (Stats.ErrorsIgnoredLineFilter) {
203 llvm::errs() << Separator << Stats.ErrorsIgnoredLineFilter
204 << " due to line filter";
205 Separator = ", ";
206 }
Alexander Kornienko5d174542014-05-07 09:06:53 +0000207 if (Stats.ErrorsIgnoredNOLINT) {
208 llvm::errs() << Separator << Stats.ErrorsIgnoredNOLINT << " NOLINT";
209 Separator = ", ";
210 }
211 if (Stats.ErrorsIgnoredCheckFilter)
212 llvm::errs() << Separator << Stats.ErrorsIgnoredCheckFilter
213 << " with check filters";
214 llvm::errs() << ").\n";
215 if (Stats.ErrorsIgnoredNonUserCode)
Aaron Ballman5a4892b2015-07-27 13:41:30 +0000216 llvm::errs() << "Use -header-filter=.* to display errors from all "
Alexander Kornienkof1d54eb2016-02-08 00:19:29 +0000217 "non-system headers. Use -system-headers to display "
218 "errors from system headers as well.\n";
Alexander Kornienko5d174542014-05-07 09:06:53 +0000219 }
220}
221
Samuel Benzaquenaedd9942014-10-23 17:23:20 +0000222static void printProfileData(const ProfileData &Profile,
223 llvm::raw_ostream &OS) {
224 // Time is first to allow for sorting by it.
225 std::vector<std::pair<llvm::TimeRecord, StringRef>> Timers;
226 TimeRecord Total;
227
Mandeep Singh Grang7c7ea7d2016-11-08 07:50:19 +0000228 for (const auto &P : Profile.Records) {
Samuel Benzaquenaedd9942014-10-23 17:23:20 +0000229 Timers.emplace_back(P.getValue(), P.getKey());
230 Total += P.getValue();
231 }
232
233 std::sort(Timers.begin(), Timers.end());
234
235 std::string Line = "===" + std::string(73, '-') + "===\n";
236 OS << Line;
237
238 if (Total.getUserTime())
239 OS << " ---User Time---";
240 if (Total.getSystemTime())
241 OS << " --System Time--";
242 if (Total.getProcessTime())
243 OS << " --User+System--";
244 OS << " ---Wall Time---";
245 if (Total.getMemUsed())
246 OS << " ---Mem---";
247 OS << " --- Name ---\n";
248
249 // Loop through all of the timing data, printing it out.
250 for (auto I = Timers.rbegin(), E = Timers.rend(); I != E; ++I) {
251 I->first.print(Total, OS);
252 OS << I->second << '\n';
253 }
254
255 Total.print(Total, OS);
256 OS << "Total\n";
257 OS << Line << "\n";
258 OS.flush();
259}
260
Benjamin Kramere7103712015-03-23 12:49:15 +0000261static std::unique_ptr<ClangTidyOptionsProvider> createOptionsProvider() {
Alexander Kornienkoc28c32d2014-09-10 11:43:09 +0000262 ClangTidyGlobalOptions GlobalOptions;
263 if (std::error_code Err = parseLineFilter(LineFilter, GlobalOptions)) {
Alexander Kornienkodad4acb2014-05-22 16:07:11 +0000264 llvm::errs() << "Invalid LineFilter: " << Err.message() << "\n\nUsage:\n";
265 llvm::cl::PrintHelpMessage(/*Hidden=*/false, /*Categorized=*/true);
Alexander Kornienkoeff4e922014-09-26 11:42:29 +0000266 return nullptr;
Alexander Kornienkodad4acb2014-05-22 16:07:11 +0000267 }
Alexander Kornienko33a9bcc2014-04-29 15:20:10 +0000268
Alexander Kornienkoe9951542014-09-24 18:36:03 +0000269 ClangTidyOptions DefaultOptions;
270 DefaultOptions.Checks = DefaultChecks;
Jonathan Roelofsd60388a2016-01-13 17:36:41 +0000271 DefaultOptions.WarningsAsErrors = "";
Alexander Kornienkoe9951542014-09-24 18:36:03 +0000272 DefaultOptions.HeaderFilterRegex = HeaderFilter;
Alexander Kornienko37f7abe2014-10-28 22:16:13 +0000273 DefaultOptions.SystemHeaders = SystemHeaders;
Alexander Kornienkoe9951542014-09-24 18:36:03 +0000274 DefaultOptions.AnalyzeTemporaryDtors = AnalyzeTemporaryDtors;
275 DefaultOptions.User = llvm::sys::Process::GetEnv("USER");
276 // USERNAME is used on Windows.
277 if (!DefaultOptions.User)
278 DefaultOptions.User = llvm::sys::Process::GetEnv("USERNAME");
Alexander Kornienkoa4695222014-06-05 13:31:45 +0000279
Alexander Kornienkoc28c32d2014-09-10 11:43:09 +0000280 ClangTidyOptions OverrideOptions;
Alexander Kornienkod53d2682014-09-04 14:23:36 +0000281 if (Checks.getNumOccurrences() > 0)
282 OverrideOptions.Checks = Checks;
Jonathan Roelofsd60388a2016-01-13 17:36:41 +0000283 if (WarningsAsErrors.getNumOccurrences() > 0)
284 OverrideOptions.WarningsAsErrors = WarningsAsErrors;
Alexander Kornienkod53d2682014-09-04 14:23:36 +0000285 if (HeaderFilter.getNumOccurrences() > 0)
286 OverrideOptions.HeaderFilterRegex = HeaderFilter;
Alexander Kornienko37f7abe2014-10-28 22:16:13 +0000287 if (SystemHeaders.getNumOccurrences() > 0)
288 OverrideOptions.SystemHeaders = SystemHeaders;
Alexander Kornienkod53d2682014-09-04 14:23:36 +0000289 if (AnalyzeTemporaryDtors.getNumOccurrences() > 0)
290 OverrideOptions.AnalyzeTemporaryDtors = AnalyzeTemporaryDtors;
291
Alexander Kornienkoeff4e922014-09-26 11:42:29 +0000292 if (!Config.empty()) {
293 if (llvm::ErrorOr<ClangTidyOptions> ParsedConfig =
294 parseConfiguration(Config)) {
Haojian Wu12e6b8f2016-04-27 09:15:01 +0000295 return llvm::make_unique<ConfigOptionsProvider>(
296 GlobalOptions,
297 ClangTidyOptions::getDefaults().mergeWith(DefaultOptions),
298 *ParsedConfig, OverrideOptions);
Alexander Kornienkoeff4e922014-09-26 11:42:29 +0000299 } else {
300 llvm::errs() << "Error: invalid configuration specified.\n"
301 << ParsedConfig.getError().message() << "\n";
302 return nullptr;
303 }
304 }
305 return llvm::make_unique<FileOptionsProvider>(GlobalOptions, DefaultOptions,
306 OverrideOptions);
307}
308
Benjamin Kramere7103712015-03-23 12:49:15 +0000309static int clangTidyMain(int argc, const char **argv) {
Alexander Kornienko65eccb42015-08-17 10:03:27 +0000310 CommonOptionsParser OptionsParser(argc, argv, ClangTidyCategory,
311 cl::ZeroOrMore);
Alexander Kornienkoeff4e922014-09-26 11:42:29 +0000312
313 auto OptionsProvider = createOptionsProvider();
314 if (!OptionsProvider)
315 return 1;
Alexander Kornienkod53d2682014-09-04 14:23:36 +0000316
Alexander Kornienko65eccb42015-08-17 10:03:27 +0000317 StringRef FileName("dummy");
318 auto PathList = OptionsParser.getSourcePathList();
319 if (!PathList.empty()) {
Alexander Kornienkoe0c900e2015-08-17 11:27:11 +0000320 FileName = PathList.front();
Alexander Kornienko65eccb42015-08-17 10:03:27 +0000321 }
Haojian Wud1218752016-07-11 07:47:04 +0000322
323 SmallString<256> FilePath(FileName);
324 if (std::error_code EC = llvm::sys::fs::make_absolute(FilePath)) {
325 llvm::errs() << "Can't make absolute path from " << FileName << ": "
326 << EC.message() << "\n";
327 }
328 ClangTidyOptions EffectiveOptions = OptionsProvider->getOptions(FilePath);
Alexander Kornienkoc28c32d2014-09-10 11:43:09 +0000329 std::vector<std::string> EnabledChecks = getCheckNames(EffectiveOptions);
Alexander Kornienkofbf92582014-06-02 20:32:06 +0000330
Haojian Wu12e6b8f2016-04-27 09:15:01 +0000331 if (ExplainConfig) {
Mandeep Singh Grang7c7ea7d2016-11-08 07:50:19 +0000332 // FIXME: Show other ClangTidyOptions' fields, like ExtraArg.
Haojian Wu12e6b8f2016-04-27 09:15:01 +0000333 std::vector<clang::tidy::ClangTidyOptionsProvider::OptionsSource>
Haojian Wud1218752016-07-11 07:47:04 +0000334 RawOptions = OptionsProvider->getRawOptions(FilePath);
Haojian Wu12e6b8f2016-04-27 09:15:01 +0000335 for (const std::string &Check : EnabledChecks) {
336 for (auto It = RawOptions.rbegin(); It != RawOptions.rend(); ++It) {
337 if (It->first.Checks && GlobList(*It->first.Checks).contains(Check)) {
338 llvm::outs() << "'" << Check << "' is enabled in the " << It->second
339 << ".\n";
340 break;
341 }
342 }
343 }
344 return 0;
345 }
346
Alexander Kornienkofb9e92b2013-12-19 19:57:05 +0000347 if (ListChecks) {
Alexander Kornienko493db092016-04-27 11:45:14 +0000348 if (EnabledChecks.empty()) {
349 llvm::errs() << "No checks enabled.\n";
350 return 1;
351 }
Alexander Kornienkofb9e92b2013-12-19 19:57:05 +0000352 llvm::outs() << "Enabled checks:";
Benjamin Kramer51a9cc92016-06-15 15:46:10 +0000353 for (const auto &CheckName : EnabledChecks)
Alexander Kornienko16ac6ce2014-03-05 13:14:32 +0000354 llvm::outs() << "\n " << CheckName;
Alexander Kornienkofb9e92b2013-12-19 19:57:05 +0000355 llvm::outs() << "\n\n";
356 return 0;
357 }
358
Alexander Kornienkod53d2682014-09-04 14:23:36 +0000359 if (DumpConfig) {
Alexander Kornienko6e0cbc82014-09-12 08:53:36 +0000360 EffectiveOptions.CheckOptions = getCheckOptions(EffectiveOptions);
Alexander Kornienko65eccb42015-08-17 10:03:27 +0000361 llvm::outs() << configurationAsText(
362 ClangTidyOptions::getDefaults().mergeWith(
363 EffectiveOptions))
Alexander Kornienkod53d2682014-09-04 14:23:36 +0000364 << "\n";
365 return 0;
366 }
367
Alexander Kornienkofbf92582014-06-02 20:32:06 +0000368 if (EnabledChecks.empty()) {
369 llvm::errs() << "Error: no checks enabled.\n";
370 llvm::cl::PrintHelpMessage(/*Hidden=*/false, /*Categorized=*/true);
371 return 1;
372 }
373
Alexander Kornienko65eccb42015-08-17 10:03:27 +0000374 if (PathList.empty()) {
375 llvm::errs() << "Error: no input files specified.\n";
376 llvm::cl::PrintHelpMessage(/*Hidden=*/false, /*Categorized=*/true);
377 return 1;
378 }
379
Samuel Benzaquenaedd9942014-10-23 17:23:20 +0000380 ProfileData Profile;
381
Alexander Kornienkoc28c32d2014-09-10 11:43:09 +0000382 std::vector<ClangTidyError> Errors;
383 ClangTidyStats Stats =
384 runClangTidy(std::move(OptionsProvider), OptionsParser.getCompilations(),
Mandeep Singh Grang7c7ea7d2016-11-08 07:50:19 +0000385 PathList, &Errors, EnableCheckProfile ? &Profile : nullptr);
Alexander Kornienko5eac3c62014-11-03 14:06:31 +0000386 bool FoundErrors =
387 std::find_if(Errors.begin(), Errors.end(), [](const ClangTidyError &E) {
388 return E.DiagLevel == ClangTidyError::Error;
389 }) != Errors.end();
390
391 const bool DisableFixes = Fix && FoundErrors && !FixErrors;
392
Jonathan Roelofsd60388a2016-01-13 17:36:41 +0000393 unsigned WErrorCount = 0;
394
Alexander Kornienko5eac3c62014-11-03 14:06:31 +0000395 // -fix-errors implies -fix.
Jonas Devlieghere73191842016-11-30 18:06:42 +0000396 handleErrors(Errors, (FixErrors || Fix) && !DisableFixes, FormatStyle,
397 WErrorCount);
Daniel Jasperd07c8402013-07-29 08:19:24 +0000398
Alexander Kornienko4153da22014-09-04 15:19:49 +0000399 if (!ExportFixes.empty() && !Errors.empty()) {
Benjamin Kramerfb98b742014-09-04 10:31:23 +0000400 std::error_code EC;
401 llvm::raw_fd_ostream OS(ExportFixes, EC, llvm::sys::fs::F_None);
402 if (EC) {
403 llvm::errs() << "Error opening output file: " << EC.message() << '\n';
404 return 1;
405 }
Alexander Kornienkoc28c32d2014-09-10 11:43:09 +0000406 exportReplacements(Errors, OS);
Benjamin Kramerfb98b742014-09-04 10:31:23 +0000407 }
408
Alexander Kornienko5d174542014-05-07 09:06:53 +0000409 printStats(Stats);
Alexander Kornienko5eac3c62014-11-03 14:06:31 +0000410 if (DisableFixes)
Alexander Kornienkob0a9b702014-12-09 15:02:17 +0000411 llvm::errs()
412 << "Found compiler errors, but -fix-errors was not specified.\n"
413 "Fixes have NOT been applied.\n\n";
Alexander Kornienko5eac3c62014-11-03 14:06:31 +0000414
Samuel Benzaquenaedd9942014-10-23 17:23:20 +0000415 if (EnableCheckProfile)
416 printProfileData(Profile, llvm::errs());
417
Jonathan Roelofsd60388a2016-01-13 17:36:41 +0000418 if (WErrorCount) {
419 StringRef Plural = WErrorCount == 1 ? "" : "s";
420 llvm::errs() << WErrorCount << " warning" << Plural << " treated as error"
421 << Plural << "\n";
422 return WErrorCount;
423 }
424
Daniel Jasperd07c8402013-07-29 08:19:24 +0000425 return 0;
426}
Daniel Jasper89bbab02013-08-04 15:56:30 +0000427
Aaron Ballmanea2f90c2015-10-02 13:27:19 +0000428// This anchor is used to force the linker to link the CERTModule.
429extern volatile int CERTModuleAnchorSource;
430static int LLVM_ATTRIBUTE_UNUSED CERTModuleAnchorDestination =
431 CERTModuleAnchorSource;
432
Piotr Padlewski5625f652016-04-29 17:58:29 +0000433// This anchor is used to force the linker to link the BoostModule.
434extern volatile int BoostModuleAnchorSource;
435static int LLVM_ATTRIBUTE_UNUSED BoostModuleAnchorDestination =
436 BoostModuleAnchorSource;
437
Daniel Jasper89bbab02013-08-04 15:56:30 +0000438// This anchor is used to force the linker to link the LLVMModule.
439extern volatile int LLVMModuleAnchorSource;
Alexander Kornienkoe1292f82015-08-19 16:54:51 +0000440static int LLVM_ATTRIBUTE_UNUSED LLVMModuleAnchorDestination =
441 LLVMModuleAnchorSource;
Daniel Jasper89bbab02013-08-04 15:56:30 +0000442
Aaron Ballmanaaa40802015-10-06 13:31:00 +0000443// This anchor is used to force the linker to link the CppCoreGuidelinesModule.
444extern volatile int CppCoreGuidelinesModuleAnchorSource;
445static int LLVM_ATTRIBUTE_UNUSED CppCoreGuidelinesModuleAnchorDestination =
446 CppCoreGuidelinesModuleAnchorSource;
447
Daniel Jasper89bbab02013-08-04 15:56:30 +0000448// This anchor is used to force the linker to link the GoogleModule.
449extern volatile int GoogleModuleAnchorSource;
Alexander Kornienkoe1292f82015-08-19 16:54:51 +0000450static int LLVM_ATTRIBUTE_UNUSED GoogleModuleAnchorDestination =
451 GoogleModuleAnchorSource;
Daniel Jasper89bbab02013-08-04 15:56:30 +0000452
Alexander Kornienko16ac6ce2014-03-05 13:14:32 +0000453// This anchor is used to force the linker to link the MiscModule.
454extern volatile int MiscModuleAnchorSource;
Alexander Kornienkoe1292f82015-08-19 16:54:51 +0000455static int LLVM_ATTRIBUTE_UNUSED MiscModuleAnchorDestination =
456 MiscModuleAnchorSource;
Alexander Kornienko16ac6ce2014-03-05 13:14:32 +0000457
Alexander Kornienkofc650862015-08-14 13:17:11 +0000458// This anchor is used to force the linker to link the ModernizeModule.
459extern volatile int ModernizeModuleAnchorSource;
Alexander Kornienkoe1292f82015-08-19 16:54:51 +0000460static int LLVM_ATTRIBUTE_UNUSED ModernizeModuleAnchorDestination =
461 ModernizeModuleAnchorSource;
Alexander Kornienkofc650862015-08-14 13:17:11 +0000462
Alexander Kornienko5e0a50c2016-08-02 20:29:35 +0000463// This anchor is used to force the linker to link the MPIModule.
464extern volatile int MPIModuleAnchorSource;
465static int LLVM_ATTRIBUTE_UNUSED MPIModuleAnchorDestination =
Mandeep Singh Grang7c7ea7d2016-11-08 07:50:19 +0000466 MPIModuleAnchorSource;
Alexander Kornienko5e0a50c2016-08-02 20:29:35 +0000467
Alexander Kornienkob959f4c2015-12-30 10:24:40 +0000468// This anchor is used to force the linker to link the PerformanceModule.
469extern volatile int PerformanceModuleAnchorSource;
470static int LLVM_ATTRIBUTE_UNUSED PerformanceModuleAnchorDestination =
471 PerformanceModuleAnchorSource;
472
Alexander Kornienko2192a8e2014-10-26 01:41:14 +0000473// This anchor is used to force the linker to link the ReadabilityModule.
474extern volatile int ReadabilityModuleAnchorSource;
Alexander Kornienkoe1292f82015-08-19 16:54:51 +0000475static int LLVM_ATTRIBUTE_UNUSED ReadabilityModuleAnchorDestination =
476 ReadabilityModuleAnchorSource;
Alexander Kornienko2192a8e2014-10-26 01:41:14 +0000477
Daniel Jasper89bbab02013-08-04 15:56:30 +0000478} // namespace tidy
479} // namespace clang
Alexander Kornienkoc28c32d2014-09-10 11:43:09 +0000480
481int main(int argc, const char **argv) {
482 return clang::tidy::clangTidyMain(argc, argv);
483}