blob: b6684d023a2e8f055150e20a025d8e31a09ffbfa [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
Ehsan Akhgarib7418d32017-02-09 18:32:02 +0000191static cl::opt<bool> Quiet("quiet", cl::desc(R"(
192Run clang-tidy in quiet mode. This suppresses
193printing statistics about ignored warnings and
194warnings treated as errors if the respective
195options are specified.
196)"),
197 cl::init(false),
198 cl::cat(ClangTidyCategory));
199
Alexander Kornienkoc28c32d2014-09-10 11:43:09 +0000200namespace clang {
201namespace tidy {
202
203static void printStats(const ClangTidyStats &Stats) {
Alexander Kornienkodad4acb2014-05-22 16:07:11 +0000204 if (Stats.errorsIgnored()) {
205 llvm::errs() << "Suppressed " << Stats.errorsIgnored() << " warnings (";
Alexander Kornienko5d174542014-05-07 09:06:53 +0000206 StringRef Separator = "";
207 if (Stats.ErrorsIgnoredNonUserCode) {
208 llvm::errs() << Stats.ErrorsIgnoredNonUserCode << " in non-user code";
209 Separator = ", ";
210 }
Alexander Kornienkodad4acb2014-05-22 16:07:11 +0000211 if (Stats.ErrorsIgnoredLineFilter) {
212 llvm::errs() << Separator << Stats.ErrorsIgnoredLineFilter
213 << " due to line filter";
214 Separator = ", ";
215 }
Alexander Kornienko5d174542014-05-07 09:06:53 +0000216 if (Stats.ErrorsIgnoredNOLINT) {
217 llvm::errs() << Separator << Stats.ErrorsIgnoredNOLINT << " NOLINT";
218 Separator = ", ";
219 }
220 if (Stats.ErrorsIgnoredCheckFilter)
221 llvm::errs() << Separator << Stats.ErrorsIgnoredCheckFilter
222 << " with check filters";
223 llvm::errs() << ").\n";
224 if (Stats.ErrorsIgnoredNonUserCode)
Aaron Ballman5a4892b2015-07-27 13:41:30 +0000225 llvm::errs() << "Use -header-filter=.* to display errors from all "
Alexander Kornienkof1d54eb2016-02-08 00:19:29 +0000226 "non-system headers. Use -system-headers to display "
227 "errors from system headers as well.\n";
Alexander Kornienko5d174542014-05-07 09:06:53 +0000228 }
229}
230
Samuel Benzaquenaedd9942014-10-23 17:23:20 +0000231static void printProfileData(const ProfileData &Profile,
232 llvm::raw_ostream &OS) {
233 // Time is first to allow for sorting by it.
234 std::vector<std::pair<llvm::TimeRecord, StringRef>> Timers;
235 TimeRecord Total;
236
Mandeep Singh Grang7c7ea7d2016-11-08 07:50:19 +0000237 for (const auto &P : Profile.Records) {
Samuel Benzaquenaedd9942014-10-23 17:23:20 +0000238 Timers.emplace_back(P.getValue(), P.getKey());
239 Total += P.getValue();
240 }
241
242 std::sort(Timers.begin(), Timers.end());
243
244 std::string Line = "===" + std::string(73, '-') + "===\n";
245 OS << Line;
246
247 if (Total.getUserTime())
248 OS << " ---User Time---";
249 if (Total.getSystemTime())
250 OS << " --System Time--";
251 if (Total.getProcessTime())
252 OS << " --User+System--";
253 OS << " ---Wall Time---";
254 if (Total.getMemUsed())
255 OS << " ---Mem---";
256 OS << " --- Name ---\n";
257
258 // Loop through all of the timing data, printing it out.
259 for (auto I = Timers.rbegin(), E = Timers.rend(); I != E; ++I) {
260 I->first.print(Total, OS);
261 OS << I->second << '\n';
262 }
263
264 Total.print(Total, OS);
265 OS << "Total\n";
266 OS << Line << "\n";
267 OS.flush();
268}
269
Benjamin Kramere7103712015-03-23 12:49:15 +0000270static std::unique_ptr<ClangTidyOptionsProvider> createOptionsProvider() {
Alexander Kornienkoc28c32d2014-09-10 11:43:09 +0000271 ClangTidyGlobalOptions GlobalOptions;
272 if (std::error_code Err = parseLineFilter(LineFilter, GlobalOptions)) {
Alexander Kornienkodad4acb2014-05-22 16:07:11 +0000273 llvm::errs() << "Invalid LineFilter: " << Err.message() << "\n\nUsage:\n";
274 llvm::cl::PrintHelpMessage(/*Hidden=*/false, /*Categorized=*/true);
Alexander Kornienkoeff4e922014-09-26 11:42:29 +0000275 return nullptr;
Alexander Kornienkodad4acb2014-05-22 16:07:11 +0000276 }
Alexander Kornienko33a9bcc2014-04-29 15:20:10 +0000277
Alexander Kornienkoe9951542014-09-24 18:36:03 +0000278 ClangTidyOptions DefaultOptions;
279 DefaultOptions.Checks = DefaultChecks;
Jonathan Roelofsd60388a2016-01-13 17:36:41 +0000280 DefaultOptions.WarningsAsErrors = "";
Alexander Kornienkoe9951542014-09-24 18:36:03 +0000281 DefaultOptions.HeaderFilterRegex = HeaderFilter;
Alexander Kornienko37f7abe2014-10-28 22:16:13 +0000282 DefaultOptions.SystemHeaders = SystemHeaders;
Alexander Kornienkoe9951542014-09-24 18:36:03 +0000283 DefaultOptions.AnalyzeTemporaryDtors = AnalyzeTemporaryDtors;
284 DefaultOptions.User = llvm::sys::Process::GetEnv("USER");
285 // USERNAME is used on Windows.
286 if (!DefaultOptions.User)
287 DefaultOptions.User = llvm::sys::Process::GetEnv("USERNAME");
Alexander Kornienkoa4695222014-06-05 13:31:45 +0000288
Alexander Kornienkoc28c32d2014-09-10 11:43:09 +0000289 ClangTidyOptions OverrideOptions;
Alexander Kornienkod53d2682014-09-04 14:23:36 +0000290 if (Checks.getNumOccurrences() > 0)
291 OverrideOptions.Checks = Checks;
Jonathan Roelofsd60388a2016-01-13 17:36:41 +0000292 if (WarningsAsErrors.getNumOccurrences() > 0)
293 OverrideOptions.WarningsAsErrors = WarningsAsErrors;
Alexander Kornienkod53d2682014-09-04 14:23:36 +0000294 if (HeaderFilter.getNumOccurrences() > 0)
295 OverrideOptions.HeaderFilterRegex = HeaderFilter;
Alexander Kornienko37f7abe2014-10-28 22:16:13 +0000296 if (SystemHeaders.getNumOccurrences() > 0)
297 OverrideOptions.SystemHeaders = SystemHeaders;
Alexander Kornienkod53d2682014-09-04 14:23:36 +0000298 if (AnalyzeTemporaryDtors.getNumOccurrences() > 0)
299 OverrideOptions.AnalyzeTemporaryDtors = AnalyzeTemporaryDtors;
300
Alexander Kornienkoeff4e922014-09-26 11:42:29 +0000301 if (!Config.empty()) {
302 if (llvm::ErrorOr<ClangTidyOptions> ParsedConfig =
303 parseConfiguration(Config)) {
Haojian Wu12e6b8f2016-04-27 09:15:01 +0000304 return llvm::make_unique<ConfigOptionsProvider>(
305 GlobalOptions,
306 ClangTidyOptions::getDefaults().mergeWith(DefaultOptions),
307 *ParsedConfig, OverrideOptions);
Alexander Kornienkoeff4e922014-09-26 11:42:29 +0000308 } else {
309 llvm::errs() << "Error: invalid configuration specified.\n"
310 << ParsedConfig.getError().message() << "\n";
311 return nullptr;
312 }
313 }
314 return llvm::make_unique<FileOptionsProvider>(GlobalOptions, DefaultOptions,
315 OverrideOptions);
316}
317
Benjamin Kramere7103712015-03-23 12:49:15 +0000318static int clangTidyMain(int argc, const char **argv) {
Alexander Kornienko65eccb42015-08-17 10:03:27 +0000319 CommonOptionsParser OptionsParser(argc, argv, ClangTidyCategory,
320 cl::ZeroOrMore);
Alexander Kornienkoeff4e922014-09-26 11:42:29 +0000321
322 auto OptionsProvider = createOptionsProvider();
323 if (!OptionsProvider)
324 return 1;
Alexander Kornienkod53d2682014-09-04 14:23:36 +0000325
Alexander Kornienko65eccb42015-08-17 10:03:27 +0000326 StringRef FileName("dummy");
327 auto PathList = OptionsParser.getSourcePathList();
328 if (!PathList.empty()) {
Alexander Kornienkoe0c900e2015-08-17 11:27:11 +0000329 FileName = PathList.front();
Alexander Kornienko65eccb42015-08-17 10:03:27 +0000330 }
Haojian Wud1218752016-07-11 07:47:04 +0000331
332 SmallString<256> FilePath(FileName);
333 if (std::error_code EC = llvm::sys::fs::make_absolute(FilePath)) {
334 llvm::errs() << "Can't make absolute path from " << FileName << ": "
335 << EC.message() << "\n";
336 }
337 ClangTidyOptions EffectiveOptions = OptionsProvider->getOptions(FilePath);
Alexander Kornienkoc28c32d2014-09-10 11:43:09 +0000338 std::vector<std::string> EnabledChecks = getCheckNames(EffectiveOptions);
Alexander Kornienkofbf92582014-06-02 20:32:06 +0000339
Haojian Wu12e6b8f2016-04-27 09:15:01 +0000340 if (ExplainConfig) {
Mandeep Singh Grang7c7ea7d2016-11-08 07:50:19 +0000341 // FIXME: Show other ClangTidyOptions' fields, like ExtraArg.
Haojian Wu12e6b8f2016-04-27 09:15:01 +0000342 std::vector<clang::tidy::ClangTidyOptionsProvider::OptionsSource>
Haojian Wud1218752016-07-11 07:47:04 +0000343 RawOptions = OptionsProvider->getRawOptions(FilePath);
Haojian Wu12e6b8f2016-04-27 09:15:01 +0000344 for (const std::string &Check : EnabledChecks) {
345 for (auto It = RawOptions.rbegin(); It != RawOptions.rend(); ++It) {
346 if (It->first.Checks && GlobList(*It->first.Checks).contains(Check)) {
347 llvm::outs() << "'" << Check << "' is enabled in the " << It->second
348 << ".\n";
349 break;
350 }
351 }
352 }
353 return 0;
354 }
355
Alexander Kornienkofb9e92b2013-12-19 19:57:05 +0000356 if (ListChecks) {
Alexander Kornienko493db092016-04-27 11:45:14 +0000357 if (EnabledChecks.empty()) {
358 llvm::errs() << "No checks enabled.\n";
359 return 1;
360 }
Alexander Kornienkofb9e92b2013-12-19 19:57:05 +0000361 llvm::outs() << "Enabled checks:";
Benjamin Kramer51a9cc92016-06-15 15:46:10 +0000362 for (const auto &CheckName : EnabledChecks)
Alexander Kornienko16ac6ce2014-03-05 13:14:32 +0000363 llvm::outs() << "\n " << CheckName;
Alexander Kornienkofb9e92b2013-12-19 19:57:05 +0000364 llvm::outs() << "\n\n";
365 return 0;
366 }
367
Alexander Kornienkod53d2682014-09-04 14:23:36 +0000368 if (DumpConfig) {
Alexander Kornienko6e0cbc82014-09-12 08:53:36 +0000369 EffectiveOptions.CheckOptions = getCheckOptions(EffectiveOptions);
Alexander Kornienko65eccb42015-08-17 10:03:27 +0000370 llvm::outs() << configurationAsText(
371 ClangTidyOptions::getDefaults().mergeWith(
372 EffectiveOptions))
Alexander Kornienkod53d2682014-09-04 14:23:36 +0000373 << "\n";
374 return 0;
375 }
376
Alexander Kornienkofbf92582014-06-02 20:32:06 +0000377 if (EnabledChecks.empty()) {
378 llvm::errs() << "Error: no checks enabled.\n";
379 llvm::cl::PrintHelpMessage(/*Hidden=*/false, /*Categorized=*/true);
380 return 1;
381 }
382
Alexander Kornienko65eccb42015-08-17 10:03:27 +0000383 if (PathList.empty()) {
384 llvm::errs() << "Error: no input files specified.\n";
385 llvm::cl::PrintHelpMessage(/*Hidden=*/false, /*Categorized=*/true);
386 return 1;
387 }
388
Samuel Benzaquenaedd9942014-10-23 17:23:20 +0000389 ProfileData Profile;
390
Alexander Kornienkoc28c32d2014-09-10 11:43:09 +0000391 std::vector<ClangTidyError> Errors;
392 ClangTidyStats Stats =
393 runClangTidy(std::move(OptionsProvider), OptionsParser.getCompilations(),
Mandeep Singh Grang7c7ea7d2016-11-08 07:50:19 +0000394 PathList, &Errors, EnableCheckProfile ? &Profile : nullptr);
Alexander Kornienko5eac3c62014-11-03 14:06:31 +0000395 bool FoundErrors =
396 std::find_if(Errors.begin(), Errors.end(), [](const ClangTidyError &E) {
397 return E.DiagLevel == ClangTidyError::Error;
398 }) != Errors.end();
399
400 const bool DisableFixes = Fix && FoundErrors && !FixErrors;
401
Jonathan Roelofsd60388a2016-01-13 17:36:41 +0000402 unsigned WErrorCount = 0;
403
Alexander Kornienko5eac3c62014-11-03 14:06:31 +0000404 // -fix-errors implies -fix.
Jonas Devlieghere73191842016-11-30 18:06:42 +0000405 handleErrors(Errors, (FixErrors || Fix) && !DisableFixes, FormatStyle,
406 WErrorCount);
Daniel Jasperd07c8402013-07-29 08:19:24 +0000407
Alexander Kornienko4153da22014-09-04 15:19:49 +0000408 if (!ExportFixes.empty() && !Errors.empty()) {
Benjamin Kramerfb98b742014-09-04 10:31:23 +0000409 std::error_code EC;
410 llvm::raw_fd_ostream OS(ExportFixes, EC, llvm::sys::fs::F_None);
411 if (EC) {
412 llvm::errs() << "Error opening output file: " << EC.message() << '\n';
413 return 1;
414 }
Alexander Kornienko563de792017-01-03 14:36:13 +0000415 exportReplacements(FilePath.str(), Errors, OS);
Benjamin Kramerfb98b742014-09-04 10:31:23 +0000416 }
417
Ehsan Akhgarib7418d32017-02-09 18:32:02 +0000418 if (!Quiet) {
419 printStats(Stats);
420 if (DisableFixes)
421 llvm::errs()
422 << "Found compiler errors, but -fix-errors was not specified.\n"
423 "Fixes have NOT been applied.\n\n";
424 }
Alexander Kornienko5eac3c62014-11-03 14:06:31 +0000425
Samuel Benzaquenaedd9942014-10-23 17:23:20 +0000426 if (EnableCheckProfile)
427 printProfileData(Profile, llvm::errs());
428
Jonathan Roelofsd60388a2016-01-13 17:36:41 +0000429 if (WErrorCount) {
Ehsan Akhgarib7418d32017-02-09 18:32:02 +0000430 if (!Quiet) {
431 StringRef Plural = WErrorCount == 1 ? "" : "s";
432 llvm::errs() << WErrorCount << " warning" << Plural << " treated as error"
433 << Plural << "\n";
434 }
Jonathan Roelofsd60388a2016-01-13 17:36:41 +0000435 return WErrorCount;
436 }
437
Daniel Jasperd07c8402013-07-29 08:19:24 +0000438 return 0;
439}
Daniel Jasper89bbab02013-08-04 15:56:30 +0000440
Aaron Ballmanea2f90c2015-10-02 13:27:19 +0000441// This anchor is used to force the linker to link the CERTModule.
442extern volatile int CERTModuleAnchorSource;
443static int LLVM_ATTRIBUTE_UNUSED CERTModuleAnchorDestination =
444 CERTModuleAnchorSource;
445
Piotr Padlewski5625f652016-04-29 17:58:29 +0000446// This anchor is used to force the linker to link the BoostModule.
447extern volatile int BoostModuleAnchorSource;
448static int LLVM_ATTRIBUTE_UNUSED BoostModuleAnchorDestination =
449 BoostModuleAnchorSource;
450
Daniel Jasper89bbab02013-08-04 15:56:30 +0000451// This anchor is used to force the linker to link the LLVMModule.
452extern volatile int LLVMModuleAnchorSource;
Alexander Kornienkoe1292f82015-08-19 16:54:51 +0000453static int LLVM_ATTRIBUTE_UNUSED LLVMModuleAnchorDestination =
454 LLVMModuleAnchorSource;
Daniel Jasper89bbab02013-08-04 15:56:30 +0000455
Aaron Ballmanaaa40802015-10-06 13:31:00 +0000456// This anchor is used to force the linker to link the CppCoreGuidelinesModule.
457extern volatile int CppCoreGuidelinesModuleAnchorSource;
458static int LLVM_ATTRIBUTE_UNUSED CppCoreGuidelinesModuleAnchorDestination =
459 CppCoreGuidelinesModuleAnchorSource;
460
Daniel Jasper89bbab02013-08-04 15:56:30 +0000461// This anchor is used to force the linker to link the GoogleModule.
462extern volatile int GoogleModuleAnchorSource;
Alexander Kornienkoe1292f82015-08-19 16:54:51 +0000463static int LLVM_ATTRIBUTE_UNUSED GoogleModuleAnchorDestination =
464 GoogleModuleAnchorSource;
Daniel Jasper89bbab02013-08-04 15:56:30 +0000465
Alexander Kornienko16ac6ce2014-03-05 13:14:32 +0000466// This anchor is used to force the linker to link the MiscModule.
467extern volatile int MiscModuleAnchorSource;
Alexander Kornienkoe1292f82015-08-19 16:54:51 +0000468static int LLVM_ATTRIBUTE_UNUSED MiscModuleAnchorDestination =
469 MiscModuleAnchorSource;
Alexander Kornienko16ac6ce2014-03-05 13:14:32 +0000470
Alexander Kornienkofc650862015-08-14 13:17:11 +0000471// This anchor is used to force the linker to link the ModernizeModule.
472extern volatile int ModernizeModuleAnchorSource;
Alexander Kornienkoe1292f82015-08-19 16:54:51 +0000473static int LLVM_ATTRIBUTE_UNUSED ModernizeModuleAnchorDestination =
474 ModernizeModuleAnchorSource;
Alexander Kornienkofc650862015-08-14 13:17:11 +0000475
Alexander Kornienko5e0a50c2016-08-02 20:29:35 +0000476// This anchor is used to force the linker to link the MPIModule.
477extern volatile int MPIModuleAnchorSource;
478static int LLVM_ATTRIBUTE_UNUSED MPIModuleAnchorDestination =
Mandeep Singh Grang7c7ea7d2016-11-08 07:50:19 +0000479 MPIModuleAnchorSource;
Alexander Kornienko5e0a50c2016-08-02 20:29:35 +0000480
Alexander Kornienkob959f4c2015-12-30 10:24:40 +0000481// This anchor is used to force the linker to link the PerformanceModule.
482extern volatile int PerformanceModuleAnchorSource;
483static int LLVM_ATTRIBUTE_UNUSED PerformanceModuleAnchorDestination =
484 PerformanceModuleAnchorSource;
485
Alexander Kornienko2192a8e2014-10-26 01:41:14 +0000486// This anchor is used to force the linker to link the ReadabilityModule.
487extern volatile int ReadabilityModuleAnchorSource;
Alexander Kornienkoe1292f82015-08-19 16:54:51 +0000488static int LLVM_ATTRIBUTE_UNUSED ReadabilityModuleAnchorDestination =
489 ReadabilityModuleAnchorSource;
Alexander Kornienko2192a8e2014-10-26 01:41:14 +0000490
Jonathan Coe3032d3c2017-02-06 22:57:14 +0000491// This anchor is used to force the linker to link the SafetyModule.
492extern volatile int SafetyModuleAnchorSource;
493static int LLVM_ATTRIBUTE_UNUSED SafetyModuleAnchorDestination =
494 SafetyModuleAnchorSource;
495
Daniel Jasper89bbab02013-08-04 15:56:30 +0000496} // namespace tidy
497} // namespace clang
Alexander Kornienkoc28c32d2014-09-10 11:43:09 +0000498
499int main(int argc, const char **argv) {
500 return clang::tidy::clangTidyMain(argc, argv);
501}