blob: ab9d935120aef2cb4a24425e44a37829997e32e7 [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 Kornienko50ab1562014-10-29 18:25:09 +000052const char DefaultChecks[] = // Enable these checks:
53 "clang-diagnostic-*," // * compiler diagnostics
54 "clang-analyzer-*," // * Static Analyzer checks
55 "-clang-analyzer-alpha*"; // * but not alpha checks: many false positives
Alexander Kornienkodad4acb2014-05-22 16:07:11 +000056
Alexander Kornienkof1d54eb2016-02-08 00:19:29 +000057static cl::opt<std::string> Checks("checks", cl::desc(R"(
58Comma-separated list of globs with optional '-'
59prefix. Globs are processed in order of
60appearance in the list. Globs without '-'
61prefix add checks with matching names to the
62set, globs with the '-' prefix remove checks
63with matching names from the set of enabled
64checks. This option's value is appended to the
65value of the 'Checks' option in .clang-tidy
66file, if any.
67)"),
68 cl::init(""), cl::cat(ClangTidyCategory));
Alexander Kornienkodad4acb2014-05-22 16:07:11 +000069
Alexander Kornienkof1d54eb2016-02-08 00:19:29 +000070static cl::opt<std::string> WarningsAsErrors("warnings-as-errors", cl::desc(R"(
71Upgrades warnings to errors. Same format as
72'-checks'.
73This option's value is appended to the value of
74the 'WarningsAsErrors' option in .clang-tidy
75file, if any.
76)"),
77 cl::init(""),
78 cl::cat(ClangTidyCategory));
Jonathan Roelofsd60388a2016-01-13 17:36:41 +000079
Alexander Kornienkof1d54eb2016-02-08 00:19:29 +000080static cl::opt<std::string> HeaderFilter("header-filter", cl::desc(R"(
81Regular expression matching the names of the
82headers to output diagnostics from. Diagnostics
83from the main file of each translation unit are
84always displayed.
85Can be used together with -line-filter.
86This option overrides the 'HeaderFilter' option
87in .clang-tidy file, if any.
88)"),
89 cl::init(""),
90 cl::cat(ClangTidyCategory));
Alexander Kornienkodad4acb2014-05-22 16:07:11 +000091
Alexander Kornienko37f7abe2014-10-28 22:16:13 +000092static cl::opt<bool>
93 SystemHeaders("system-headers",
Alexander Kornienko5eac3c62014-11-03 14:06:31 +000094 cl::desc("Display the errors from system headers."),
Alexander Kornienko37f7abe2014-10-28 22:16:13 +000095 cl::init(false), cl::cat(ClangTidyCategory));
Alexander Kornienkodad4acb2014-05-22 16:07:11 +000096static cl::opt<std::string>
Alexander Kornienkof1d54eb2016-02-08 00:19:29 +000097 LineFilter("line-filter",
98 cl::desc(R"(
99List of files with line ranges to filter the
100warnings. Can be used together with
101-header-filter. The format of the list is a
102JSON array of objects:
103 [
104 {"name":"file1.cpp","lines":[[1,3],[5,7]]},
105 {"name":"file2.h"}
106 ]
107)"),
108 cl::init(""), cl::cat(ClangTidyCategory));
Alexander Kornienkodad4acb2014-05-22 16:07:11 +0000109
Alexander Kornienkof1d54eb2016-02-08 00:19:29 +0000110static cl::opt<bool> Fix("fix", cl::desc(R"(
111Apply suggested fixes. Without -fix-errors
112clang-tidy will bail out if any compilation
113errors were found.
114)"),
115 cl::init(false), cl::cat(ClangTidyCategory));
Alexander Kornienko5eac3c62014-11-03 14:06:31 +0000116
Alexander Kornienkof1d54eb2016-02-08 00:19:29 +0000117static cl::opt<bool> FixErrors("fix-errors", cl::desc(R"(
118Apply suggested fixes even if compilation
119errors were found. If compiler errors have
120attached fix-its, clang-tidy will apply them as
121well.
122)"),
123 cl::init(false), cl::cat(ClangTidyCategory));
Daniel Jasperd07c8402013-07-29 08:19:24 +0000124
Alexander Kornienkof1d54eb2016-02-08 00:19:29 +0000125static cl::opt<bool> ListChecks("list-checks", cl::desc(R"(
126List all enabled checks and exit. Use with
127-checks=* to list all available checks.
128)"),
129 cl::init(false), cl::cat(ClangTidyCategory));
Daniel Jasperd07c8402013-07-29 08:19:24 +0000130
Haojian Wu12e6b8f2016-04-27 09:15:01 +0000131static cl::opt<bool> ExplainConfig("explain-config", cl::desc(R"(
Haojian Wue5555e22016-09-22 14:36:43 +0000132For each enabled check explains, where it is
133enabled, i.e. in clang-tidy binary, command
134line or a specific configuration file.
Haojian Wu12e6b8f2016-04-27 09:15:01 +0000135)"),
136 cl::init(false), cl::cat(ClangTidyCategory));
137
Alexander Kornienkof1d54eb2016-02-08 00:19:29 +0000138static cl::opt<std::string> Config("config", cl::desc(R"(
139Specifies a configuration in YAML/JSON format:
140 -config="{Checks: '*',
141 CheckOptions: [{key: x,
142 value: y}]}"
143When the value is empty, clang-tidy will
144attempt to find a file named .clang-tidy for
145each source file in its parent directories.
146)"),
147 cl::init(""), cl::cat(ClangTidyCategory));
Alexander Kornienkoeff4e922014-09-26 11:42:29 +0000148
Alexander Kornienkof1d54eb2016-02-08 00:19:29 +0000149static cl::opt<bool> DumpConfig("dump-config", cl::desc(R"(
150Dumps configuration in the YAML format to
151stdout. This option can be used along with a
152file name (and '--' if the file is outside of a
153project with configured compilation database).
154The configuration used for this file will be
155printed.
156Use along with -checks=* to include
157configuration of all checks.
158)"),
159 cl::init(false), cl::cat(ClangTidyCategory));
Alexander Kornienkod53d2682014-09-04 14:23:36 +0000160
Alexander Kornienkof1d54eb2016-02-08 00:19:29 +0000161static cl::opt<bool> EnableCheckProfile("enable-check-profile", cl::desc(R"(
162Enable per-check timing profiles, and print a
163report to stderr.
164)"),
165 cl::init(false),
166 cl::cat(ClangTidyCategory));
Samuel Benzaquenaedd9942014-10-23 17:23:20 +0000167
Alexander Kornienkof1d54eb2016-02-08 00:19:29 +0000168static cl::opt<bool> AnalyzeTemporaryDtors("analyze-temporary-dtors",
169 cl::desc(R"(
170Enable temporary destructor-aware analysis in
171clang-analyzer- checks.
172This option overrides the value read from a
173.clang-tidy file.
174)"),
175 cl::init(false),
176 cl::cat(ClangTidyCategory));
Alex McCarthyfec08c72014-04-30 14:09:24 +0000177
Alexander Kornienkof1d54eb2016-02-08 00:19:29 +0000178static cl::opt<std::string> ExportFixes("export-fixes", cl::desc(R"(
179YAML file to store suggested fixes in. The
Kirill Bobyrev405699e2016-08-19 09:36:14 +0000180stored fixes can be applied to the input source
Alexander Kornienkof1d54eb2016-02-08 00:19:29 +0000181code with clang-apply-replacements.
182)"),
183 cl::value_desc("filename"),
184 cl::cat(ClangTidyCategory));
Benjamin Kramerfb98b742014-09-04 10:31:23 +0000185
Alexander Kornienkoc28c32d2014-09-10 11:43:09 +0000186namespace clang {
187namespace tidy {
188
189static void printStats(const ClangTidyStats &Stats) {
Alexander Kornienkodad4acb2014-05-22 16:07:11 +0000190 if (Stats.errorsIgnored()) {
191 llvm::errs() << "Suppressed " << Stats.errorsIgnored() << " warnings (";
Alexander Kornienko5d174542014-05-07 09:06:53 +0000192 StringRef Separator = "";
193 if (Stats.ErrorsIgnoredNonUserCode) {
194 llvm::errs() << Stats.ErrorsIgnoredNonUserCode << " in non-user code";
195 Separator = ", ";
196 }
Alexander Kornienkodad4acb2014-05-22 16:07:11 +0000197 if (Stats.ErrorsIgnoredLineFilter) {
198 llvm::errs() << Separator << Stats.ErrorsIgnoredLineFilter
199 << " due to line filter";
200 Separator = ", ";
201 }
Alexander Kornienko5d174542014-05-07 09:06:53 +0000202 if (Stats.ErrorsIgnoredNOLINT) {
203 llvm::errs() << Separator << Stats.ErrorsIgnoredNOLINT << " NOLINT";
204 Separator = ", ";
205 }
206 if (Stats.ErrorsIgnoredCheckFilter)
207 llvm::errs() << Separator << Stats.ErrorsIgnoredCheckFilter
208 << " with check filters";
209 llvm::errs() << ").\n";
210 if (Stats.ErrorsIgnoredNonUserCode)
Aaron Ballman5a4892b2015-07-27 13:41:30 +0000211 llvm::errs() << "Use -header-filter=.* to display errors from all "
Alexander Kornienkof1d54eb2016-02-08 00:19:29 +0000212 "non-system headers. Use -system-headers to display "
213 "errors from system headers as well.\n";
Alexander Kornienko5d174542014-05-07 09:06:53 +0000214 }
215}
216
Samuel Benzaquenaedd9942014-10-23 17:23:20 +0000217static void printProfileData(const ProfileData &Profile,
218 llvm::raw_ostream &OS) {
219 // Time is first to allow for sorting by it.
220 std::vector<std::pair<llvm::TimeRecord, StringRef>> Timers;
221 TimeRecord Total;
222
223 for (const auto& P : Profile.Records) {
224 Timers.emplace_back(P.getValue(), P.getKey());
225 Total += P.getValue();
226 }
227
228 std::sort(Timers.begin(), Timers.end());
229
230 std::string Line = "===" + std::string(73, '-') + "===\n";
231 OS << Line;
232
233 if (Total.getUserTime())
234 OS << " ---User Time---";
235 if (Total.getSystemTime())
236 OS << " --System Time--";
237 if (Total.getProcessTime())
238 OS << " --User+System--";
239 OS << " ---Wall Time---";
240 if (Total.getMemUsed())
241 OS << " ---Mem---";
242 OS << " --- Name ---\n";
243
244 // Loop through all of the timing data, printing it out.
245 for (auto I = Timers.rbegin(), E = Timers.rend(); I != E; ++I) {
246 I->first.print(Total, OS);
247 OS << I->second << '\n';
248 }
249
250 Total.print(Total, OS);
251 OS << "Total\n";
252 OS << Line << "\n";
253 OS.flush();
254}
255
Benjamin Kramere7103712015-03-23 12:49:15 +0000256static std::unique_ptr<ClangTidyOptionsProvider> createOptionsProvider() {
Alexander Kornienkoc28c32d2014-09-10 11:43:09 +0000257 ClangTidyGlobalOptions GlobalOptions;
258 if (std::error_code Err = parseLineFilter(LineFilter, GlobalOptions)) {
Alexander Kornienkodad4acb2014-05-22 16:07:11 +0000259 llvm::errs() << "Invalid LineFilter: " << Err.message() << "\n\nUsage:\n";
260 llvm::cl::PrintHelpMessage(/*Hidden=*/false, /*Categorized=*/true);
Alexander Kornienkoeff4e922014-09-26 11:42:29 +0000261 return nullptr;
Alexander Kornienkodad4acb2014-05-22 16:07:11 +0000262 }
Alexander Kornienko33a9bcc2014-04-29 15:20:10 +0000263
Alexander Kornienkoe9951542014-09-24 18:36:03 +0000264 ClangTidyOptions DefaultOptions;
265 DefaultOptions.Checks = DefaultChecks;
Jonathan Roelofsd60388a2016-01-13 17:36:41 +0000266 DefaultOptions.WarningsAsErrors = "";
Alexander Kornienkoe9951542014-09-24 18:36:03 +0000267 DefaultOptions.HeaderFilterRegex = HeaderFilter;
Alexander Kornienko37f7abe2014-10-28 22:16:13 +0000268 DefaultOptions.SystemHeaders = SystemHeaders;
Alexander Kornienkoe9951542014-09-24 18:36:03 +0000269 DefaultOptions.AnalyzeTemporaryDtors = AnalyzeTemporaryDtors;
270 DefaultOptions.User = llvm::sys::Process::GetEnv("USER");
271 // USERNAME is used on Windows.
272 if (!DefaultOptions.User)
273 DefaultOptions.User = llvm::sys::Process::GetEnv("USERNAME");
Alexander Kornienkoa4695222014-06-05 13:31:45 +0000274
Alexander Kornienkoc28c32d2014-09-10 11:43:09 +0000275 ClangTidyOptions OverrideOptions;
Alexander Kornienkod53d2682014-09-04 14:23:36 +0000276 if (Checks.getNumOccurrences() > 0)
277 OverrideOptions.Checks = Checks;
Jonathan Roelofsd60388a2016-01-13 17:36:41 +0000278 if (WarningsAsErrors.getNumOccurrences() > 0)
279 OverrideOptions.WarningsAsErrors = WarningsAsErrors;
Alexander Kornienkod53d2682014-09-04 14:23:36 +0000280 if (HeaderFilter.getNumOccurrences() > 0)
281 OverrideOptions.HeaderFilterRegex = HeaderFilter;
Alexander Kornienko37f7abe2014-10-28 22:16:13 +0000282 if (SystemHeaders.getNumOccurrences() > 0)
283 OverrideOptions.SystemHeaders = SystemHeaders;
Alexander Kornienkod53d2682014-09-04 14:23:36 +0000284 if (AnalyzeTemporaryDtors.getNumOccurrences() > 0)
285 OverrideOptions.AnalyzeTemporaryDtors = AnalyzeTemporaryDtors;
286
Alexander Kornienkoeff4e922014-09-26 11:42:29 +0000287 if (!Config.empty()) {
288 if (llvm::ErrorOr<ClangTidyOptions> ParsedConfig =
289 parseConfiguration(Config)) {
Haojian Wu12e6b8f2016-04-27 09:15:01 +0000290 return llvm::make_unique<ConfigOptionsProvider>(
291 GlobalOptions,
292 ClangTidyOptions::getDefaults().mergeWith(DefaultOptions),
293 *ParsedConfig, OverrideOptions);
Alexander Kornienkoeff4e922014-09-26 11:42:29 +0000294 } else {
295 llvm::errs() << "Error: invalid configuration specified.\n"
296 << ParsedConfig.getError().message() << "\n";
297 return nullptr;
298 }
299 }
300 return llvm::make_unique<FileOptionsProvider>(GlobalOptions, DefaultOptions,
301 OverrideOptions);
302}
303
Benjamin Kramere7103712015-03-23 12:49:15 +0000304static int clangTidyMain(int argc, const char **argv) {
Alexander Kornienko65eccb42015-08-17 10:03:27 +0000305 CommonOptionsParser OptionsParser(argc, argv, ClangTidyCategory,
306 cl::ZeroOrMore);
Alexander Kornienkoeff4e922014-09-26 11:42:29 +0000307
308 auto OptionsProvider = createOptionsProvider();
309 if (!OptionsProvider)
310 return 1;
Alexander Kornienkod53d2682014-09-04 14:23:36 +0000311
Alexander Kornienko65eccb42015-08-17 10:03:27 +0000312 StringRef FileName("dummy");
313 auto PathList = OptionsParser.getSourcePathList();
314 if (!PathList.empty()) {
Alexander Kornienkoe0c900e2015-08-17 11:27:11 +0000315 FileName = PathList.front();
Alexander Kornienko65eccb42015-08-17 10:03:27 +0000316 }
Haojian Wud1218752016-07-11 07:47:04 +0000317
318 SmallString<256> FilePath(FileName);
319 if (std::error_code EC = llvm::sys::fs::make_absolute(FilePath)) {
320 llvm::errs() << "Can't make absolute path from " << FileName << ": "
321 << EC.message() << "\n";
322 }
323 ClangTidyOptions EffectiveOptions = OptionsProvider->getOptions(FilePath);
Alexander Kornienkoc28c32d2014-09-10 11:43:09 +0000324 std::vector<std::string> EnabledChecks = getCheckNames(EffectiveOptions);
Alexander Kornienkofbf92582014-06-02 20:32:06 +0000325
Haojian Wu12e6b8f2016-04-27 09:15:01 +0000326 if (ExplainConfig) {
327 //FIXME: Show other ClangTidyOptions' fields, like ExtraArg.
328 std::vector<clang::tidy::ClangTidyOptionsProvider::OptionsSource>
Haojian Wud1218752016-07-11 07:47:04 +0000329 RawOptions = OptionsProvider->getRawOptions(FilePath);
Haojian Wu12e6b8f2016-04-27 09:15:01 +0000330 for (const std::string &Check : EnabledChecks) {
331 for (auto It = RawOptions.rbegin(); It != RawOptions.rend(); ++It) {
332 if (It->first.Checks && GlobList(*It->first.Checks).contains(Check)) {
333 llvm::outs() << "'" << Check << "' is enabled in the " << It->second
334 << ".\n";
335 break;
336 }
337 }
338 }
339 return 0;
340 }
341
Alexander Kornienkofb9e92b2013-12-19 19:57:05 +0000342 if (ListChecks) {
Alexander Kornienko493db092016-04-27 11:45:14 +0000343 if (EnabledChecks.empty()) {
344 llvm::errs() << "No checks enabled.\n";
345 return 1;
346 }
Alexander Kornienkofb9e92b2013-12-19 19:57:05 +0000347 llvm::outs() << "Enabled checks:";
Benjamin Kramer51a9cc92016-06-15 15:46:10 +0000348 for (const auto &CheckName : EnabledChecks)
Alexander Kornienko16ac6ce2014-03-05 13:14:32 +0000349 llvm::outs() << "\n " << CheckName;
Alexander Kornienkofb9e92b2013-12-19 19:57:05 +0000350 llvm::outs() << "\n\n";
351 return 0;
352 }
353
Alexander Kornienkod53d2682014-09-04 14:23:36 +0000354 if (DumpConfig) {
Alexander Kornienko6e0cbc82014-09-12 08:53:36 +0000355 EffectiveOptions.CheckOptions = getCheckOptions(EffectiveOptions);
Alexander Kornienko65eccb42015-08-17 10:03:27 +0000356 llvm::outs() << configurationAsText(
357 ClangTidyOptions::getDefaults().mergeWith(
358 EffectiveOptions))
Alexander Kornienkod53d2682014-09-04 14:23:36 +0000359 << "\n";
360 return 0;
361 }
362
Alexander Kornienkofbf92582014-06-02 20:32:06 +0000363 if (EnabledChecks.empty()) {
364 llvm::errs() << "Error: no checks enabled.\n";
365 llvm::cl::PrintHelpMessage(/*Hidden=*/false, /*Categorized=*/true);
366 return 1;
367 }
368
Alexander Kornienko65eccb42015-08-17 10:03:27 +0000369 if (PathList.empty()) {
370 llvm::errs() << "Error: no input files specified.\n";
371 llvm::cl::PrintHelpMessage(/*Hidden=*/false, /*Categorized=*/true);
372 return 1;
373 }
374
Samuel Benzaquenaedd9942014-10-23 17:23:20 +0000375 ProfileData Profile;
376
Alexander Kornienkoc28c32d2014-09-10 11:43:09 +0000377 std::vector<ClangTidyError> Errors;
378 ClangTidyStats Stats =
379 runClangTidy(std::move(OptionsProvider), OptionsParser.getCompilations(),
Alexander Kornienko65eccb42015-08-17 10:03:27 +0000380 PathList, &Errors,
Samuel Benzaquenaedd9942014-10-23 17:23:20 +0000381 EnableCheckProfile ? &Profile : nullptr);
Alexander Kornienko5eac3c62014-11-03 14:06:31 +0000382 bool FoundErrors =
383 std::find_if(Errors.begin(), Errors.end(), [](const ClangTidyError &E) {
384 return E.DiagLevel == ClangTidyError::Error;
385 }) != Errors.end();
386
387 const bool DisableFixes = Fix && FoundErrors && !FixErrors;
388
Jonathan Roelofsd60388a2016-01-13 17:36:41 +0000389 unsigned WErrorCount = 0;
390
Alexander Kornienko5eac3c62014-11-03 14:06:31 +0000391 // -fix-errors implies -fix.
Jonathan Roelofsd60388a2016-01-13 17:36:41 +0000392 handleErrors(Errors, (FixErrors || Fix) && !DisableFixes, WErrorCount);
Daniel Jasperd07c8402013-07-29 08:19:24 +0000393
Alexander Kornienko4153da22014-09-04 15:19:49 +0000394 if (!ExportFixes.empty() && !Errors.empty()) {
Benjamin Kramerfb98b742014-09-04 10:31:23 +0000395 std::error_code EC;
396 llvm::raw_fd_ostream OS(ExportFixes, EC, llvm::sys::fs::F_None);
397 if (EC) {
398 llvm::errs() << "Error opening output file: " << EC.message() << '\n';
399 return 1;
400 }
Alexander Kornienkoc28c32d2014-09-10 11:43:09 +0000401 exportReplacements(Errors, OS);
Benjamin Kramerfb98b742014-09-04 10:31:23 +0000402 }
403
Alexander Kornienko5d174542014-05-07 09:06:53 +0000404 printStats(Stats);
Alexander Kornienko5eac3c62014-11-03 14:06:31 +0000405 if (DisableFixes)
Alexander Kornienkob0a9b702014-12-09 15:02:17 +0000406 llvm::errs()
407 << "Found compiler errors, but -fix-errors was not specified.\n"
408 "Fixes have NOT been applied.\n\n";
Alexander Kornienko5eac3c62014-11-03 14:06:31 +0000409
Samuel Benzaquenaedd9942014-10-23 17:23:20 +0000410 if (EnableCheckProfile)
411 printProfileData(Profile, llvm::errs());
412
Jonathan Roelofsd60388a2016-01-13 17:36:41 +0000413 if (WErrorCount) {
414 StringRef Plural = WErrorCount == 1 ? "" : "s";
415 llvm::errs() << WErrorCount << " warning" << Plural << " treated as error"
416 << Plural << "\n";
417 return WErrorCount;
418 }
419
Daniel Jasperd07c8402013-07-29 08:19:24 +0000420 return 0;
421}
Daniel Jasper89bbab02013-08-04 15:56:30 +0000422
Aaron Ballmanea2f90c2015-10-02 13:27:19 +0000423// This anchor is used to force the linker to link the CERTModule.
424extern volatile int CERTModuleAnchorSource;
425static int LLVM_ATTRIBUTE_UNUSED CERTModuleAnchorDestination =
426 CERTModuleAnchorSource;
427
Piotr Padlewski5625f652016-04-29 17:58:29 +0000428// This anchor is used to force the linker to link the BoostModule.
429extern volatile int BoostModuleAnchorSource;
430static int LLVM_ATTRIBUTE_UNUSED BoostModuleAnchorDestination =
431 BoostModuleAnchorSource;
432
Daniel Jasper89bbab02013-08-04 15:56:30 +0000433// This anchor is used to force the linker to link the LLVMModule.
434extern volatile int LLVMModuleAnchorSource;
Alexander Kornienkoe1292f82015-08-19 16:54:51 +0000435static int LLVM_ATTRIBUTE_UNUSED LLVMModuleAnchorDestination =
436 LLVMModuleAnchorSource;
Daniel Jasper89bbab02013-08-04 15:56:30 +0000437
Aaron Ballmanaaa40802015-10-06 13:31:00 +0000438// This anchor is used to force the linker to link the CppCoreGuidelinesModule.
439extern volatile int CppCoreGuidelinesModuleAnchorSource;
440static int LLVM_ATTRIBUTE_UNUSED CppCoreGuidelinesModuleAnchorDestination =
441 CppCoreGuidelinesModuleAnchorSource;
442
Daniel Jasper89bbab02013-08-04 15:56:30 +0000443// This anchor is used to force the linker to link the GoogleModule.
444extern volatile int GoogleModuleAnchorSource;
Alexander Kornienkoe1292f82015-08-19 16:54:51 +0000445static int LLVM_ATTRIBUTE_UNUSED GoogleModuleAnchorDestination =
446 GoogleModuleAnchorSource;
Daniel Jasper89bbab02013-08-04 15:56:30 +0000447
Alexander Kornienko16ac6ce2014-03-05 13:14:32 +0000448// This anchor is used to force the linker to link the MiscModule.
449extern volatile int MiscModuleAnchorSource;
Alexander Kornienkoe1292f82015-08-19 16:54:51 +0000450static int LLVM_ATTRIBUTE_UNUSED MiscModuleAnchorDestination =
451 MiscModuleAnchorSource;
Alexander Kornienko16ac6ce2014-03-05 13:14:32 +0000452
Alexander Kornienkofc650862015-08-14 13:17:11 +0000453// This anchor is used to force the linker to link the ModernizeModule.
454extern volatile int ModernizeModuleAnchorSource;
Alexander Kornienkoe1292f82015-08-19 16:54:51 +0000455static int LLVM_ATTRIBUTE_UNUSED ModernizeModuleAnchorDestination =
456 ModernizeModuleAnchorSource;
Alexander Kornienkofc650862015-08-14 13:17:11 +0000457
Alexander Kornienko5e0a50c2016-08-02 20:29:35 +0000458// This anchor is used to force the linker to link the MPIModule.
459extern volatile int MPIModuleAnchorSource;
460static int LLVM_ATTRIBUTE_UNUSED MPIModuleAnchorDestination =
461 MPIModuleAnchorSource;
462
Alexander Kornienkob959f4c2015-12-30 10:24:40 +0000463// This anchor is used to force the linker to link the PerformanceModule.
464extern volatile int PerformanceModuleAnchorSource;
465static int LLVM_ATTRIBUTE_UNUSED PerformanceModuleAnchorDestination =
466 PerformanceModuleAnchorSource;
467
Alexander Kornienko2192a8e2014-10-26 01:41:14 +0000468// This anchor is used to force the linker to link the ReadabilityModule.
469extern volatile int ReadabilityModuleAnchorSource;
Alexander Kornienkoe1292f82015-08-19 16:54:51 +0000470static int LLVM_ATTRIBUTE_UNUSED ReadabilityModuleAnchorDestination =
471 ReadabilityModuleAnchorSource;
Alexander Kornienko2192a8e2014-10-26 01:41:14 +0000472
Daniel Jasper89bbab02013-08-04 15:56:30 +0000473} // namespace tidy
474} // namespace clang
Alexander Kornienkoc28c32d2014-09-10 11:43:09 +0000475
476int main(int argc, const char **argv) {
477 return clang::tidy::clangTidyMain(argc, argv);
478}