blob: e5a44fc9b9af6d52b1cc4a252079d20ed72ec19b [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"(
132for each enabled check explains, where it is enabled, i.e. in clang-tidy binary,
133command line or a specific configuration file.
134)"),
135 cl::init(false), cl::cat(ClangTidyCategory));
136
Alexander Kornienkof1d54eb2016-02-08 00:19:29 +0000137static cl::opt<std::string> Config("config", cl::desc(R"(
138Specifies a configuration in YAML/JSON format:
139 -config="{Checks: '*',
140 CheckOptions: [{key: x,
141 value: y}]}"
142When the value is empty, clang-tidy will
143attempt to find a file named .clang-tidy for
144each source file in its parent directories.
145)"),
146 cl::init(""), cl::cat(ClangTidyCategory));
Alexander Kornienkoeff4e922014-09-26 11:42:29 +0000147
Alexander Kornienkof1d54eb2016-02-08 00:19:29 +0000148static cl::opt<bool> DumpConfig("dump-config", cl::desc(R"(
149Dumps configuration in the YAML format to
150stdout. This option can be used along with a
151file name (and '--' if the file is outside of a
152project with configured compilation database).
153The configuration used for this file will be
154printed.
155Use along with -checks=* to include
156configuration of all checks.
157)"),
158 cl::init(false), cl::cat(ClangTidyCategory));
Alexander Kornienkod53d2682014-09-04 14:23:36 +0000159
Alexander Kornienkof1d54eb2016-02-08 00:19:29 +0000160static cl::opt<bool> EnableCheckProfile("enable-check-profile", cl::desc(R"(
161Enable per-check timing profiles, and print a
162report to stderr.
163)"),
164 cl::init(false),
165 cl::cat(ClangTidyCategory));
Samuel Benzaquenaedd9942014-10-23 17:23:20 +0000166
Alexander Kornienkof1d54eb2016-02-08 00:19:29 +0000167static cl::opt<bool> AnalyzeTemporaryDtors("analyze-temporary-dtors",
168 cl::desc(R"(
169Enable temporary destructor-aware analysis in
170clang-analyzer- checks.
171This option overrides the value read from a
172.clang-tidy file.
173)"),
174 cl::init(false),
175 cl::cat(ClangTidyCategory));
Alex McCarthyfec08c72014-04-30 14:09:24 +0000176
Alexander Kornienkof1d54eb2016-02-08 00:19:29 +0000177static cl::opt<std::string> ExportFixes("export-fixes", cl::desc(R"(
178YAML file to store suggested fixes in. The
Kirill Bobyrev405699e2016-08-19 09:36:14 +0000179stored fixes can be applied to the input source
Alexander Kornienkof1d54eb2016-02-08 00:19:29 +0000180code with clang-apply-replacements.
181)"),
182 cl::value_desc("filename"),
183 cl::cat(ClangTidyCategory));
Benjamin Kramerfb98b742014-09-04 10:31:23 +0000184
Alexander Kornienkoc28c32d2014-09-10 11:43:09 +0000185namespace clang {
186namespace tidy {
187
188static void printStats(const ClangTidyStats &Stats) {
Alexander Kornienkodad4acb2014-05-22 16:07:11 +0000189 if (Stats.errorsIgnored()) {
190 llvm::errs() << "Suppressed " << Stats.errorsIgnored() << " warnings (";
Alexander Kornienko5d174542014-05-07 09:06:53 +0000191 StringRef Separator = "";
192 if (Stats.ErrorsIgnoredNonUserCode) {
193 llvm::errs() << Stats.ErrorsIgnoredNonUserCode << " in non-user code";
194 Separator = ", ";
195 }
Alexander Kornienkodad4acb2014-05-22 16:07:11 +0000196 if (Stats.ErrorsIgnoredLineFilter) {
197 llvm::errs() << Separator << Stats.ErrorsIgnoredLineFilter
198 << " due to line filter";
199 Separator = ", ";
200 }
Alexander Kornienko5d174542014-05-07 09:06:53 +0000201 if (Stats.ErrorsIgnoredNOLINT) {
202 llvm::errs() << Separator << Stats.ErrorsIgnoredNOLINT << " NOLINT";
203 Separator = ", ";
204 }
205 if (Stats.ErrorsIgnoredCheckFilter)
206 llvm::errs() << Separator << Stats.ErrorsIgnoredCheckFilter
207 << " with check filters";
208 llvm::errs() << ").\n";
209 if (Stats.ErrorsIgnoredNonUserCode)
Aaron Ballman5a4892b2015-07-27 13:41:30 +0000210 llvm::errs() << "Use -header-filter=.* to display errors from all "
Alexander Kornienkof1d54eb2016-02-08 00:19:29 +0000211 "non-system headers. Use -system-headers to display "
212 "errors from system headers as well.\n";
Alexander Kornienko5d174542014-05-07 09:06:53 +0000213 }
214}
215
Samuel Benzaquenaedd9942014-10-23 17:23:20 +0000216static void printProfileData(const ProfileData &Profile,
217 llvm::raw_ostream &OS) {
218 // Time is first to allow for sorting by it.
219 std::vector<std::pair<llvm::TimeRecord, StringRef>> Timers;
220 TimeRecord Total;
221
222 for (const auto& P : Profile.Records) {
223 Timers.emplace_back(P.getValue(), P.getKey());
224 Total += P.getValue();
225 }
226
227 std::sort(Timers.begin(), Timers.end());
228
229 std::string Line = "===" + std::string(73, '-') + "===\n";
230 OS << Line;
231
232 if (Total.getUserTime())
233 OS << " ---User Time---";
234 if (Total.getSystemTime())
235 OS << " --System Time--";
236 if (Total.getProcessTime())
237 OS << " --User+System--";
238 OS << " ---Wall Time---";
239 if (Total.getMemUsed())
240 OS << " ---Mem---";
241 OS << " --- Name ---\n";
242
243 // Loop through all of the timing data, printing it out.
244 for (auto I = Timers.rbegin(), E = Timers.rend(); I != E; ++I) {
245 I->first.print(Total, OS);
246 OS << I->second << '\n';
247 }
248
249 Total.print(Total, OS);
250 OS << "Total\n";
251 OS << Line << "\n";
252 OS.flush();
253}
254
Benjamin Kramere7103712015-03-23 12:49:15 +0000255static std::unique_ptr<ClangTidyOptionsProvider> createOptionsProvider() {
Alexander Kornienkoc28c32d2014-09-10 11:43:09 +0000256 ClangTidyGlobalOptions GlobalOptions;
257 if (std::error_code Err = parseLineFilter(LineFilter, GlobalOptions)) {
Alexander Kornienkodad4acb2014-05-22 16:07:11 +0000258 llvm::errs() << "Invalid LineFilter: " << Err.message() << "\n\nUsage:\n";
259 llvm::cl::PrintHelpMessage(/*Hidden=*/false, /*Categorized=*/true);
Alexander Kornienkoeff4e922014-09-26 11:42:29 +0000260 return nullptr;
Alexander Kornienkodad4acb2014-05-22 16:07:11 +0000261 }
Alexander Kornienko33a9bcc2014-04-29 15:20:10 +0000262
Alexander Kornienkoe9951542014-09-24 18:36:03 +0000263 ClangTidyOptions DefaultOptions;
264 DefaultOptions.Checks = DefaultChecks;
Jonathan Roelofsd60388a2016-01-13 17:36:41 +0000265 DefaultOptions.WarningsAsErrors = "";
Alexander Kornienkoe9951542014-09-24 18:36:03 +0000266 DefaultOptions.HeaderFilterRegex = HeaderFilter;
Alexander Kornienko37f7abe2014-10-28 22:16:13 +0000267 DefaultOptions.SystemHeaders = SystemHeaders;
Alexander Kornienkoe9951542014-09-24 18:36:03 +0000268 DefaultOptions.AnalyzeTemporaryDtors = AnalyzeTemporaryDtors;
269 DefaultOptions.User = llvm::sys::Process::GetEnv("USER");
270 // USERNAME is used on Windows.
271 if (!DefaultOptions.User)
272 DefaultOptions.User = llvm::sys::Process::GetEnv("USERNAME");
Alexander Kornienkoa4695222014-06-05 13:31:45 +0000273
Alexander Kornienkoc28c32d2014-09-10 11:43:09 +0000274 ClangTidyOptions OverrideOptions;
Alexander Kornienkod53d2682014-09-04 14:23:36 +0000275 if (Checks.getNumOccurrences() > 0)
276 OverrideOptions.Checks = Checks;
Jonathan Roelofsd60388a2016-01-13 17:36:41 +0000277 if (WarningsAsErrors.getNumOccurrences() > 0)
278 OverrideOptions.WarningsAsErrors = WarningsAsErrors;
Alexander Kornienkod53d2682014-09-04 14:23:36 +0000279 if (HeaderFilter.getNumOccurrences() > 0)
280 OverrideOptions.HeaderFilterRegex = HeaderFilter;
Alexander Kornienko37f7abe2014-10-28 22:16:13 +0000281 if (SystemHeaders.getNumOccurrences() > 0)
282 OverrideOptions.SystemHeaders = SystemHeaders;
Alexander Kornienkod53d2682014-09-04 14:23:36 +0000283 if (AnalyzeTemporaryDtors.getNumOccurrences() > 0)
284 OverrideOptions.AnalyzeTemporaryDtors = AnalyzeTemporaryDtors;
285
Alexander Kornienkoeff4e922014-09-26 11:42:29 +0000286 if (!Config.empty()) {
287 if (llvm::ErrorOr<ClangTidyOptions> ParsedConfig =
288 parseConfiguration(Config)) {
Haojian Wu12e6b8f2016-04-27 09:15:01 +0000289 return llvm::make_unique<ConfigOptionsProvider>(
290 GlobalOptions,
291 ClangTidyOptions::getDefaults().mergeWith(DefaultOptions),
292 *ParsedConfig, OverrideOptions);
Alexander Kornienkoeff4e922014-09-26 11:42:29 +0000293 } else {
294 llvm::errs() << "Error: invalid configuration specified.\n"
295 << ParsedConfig.getError().message() << "\n";
296 return nullptr;
297 }
298 }
299 return llvm::make_unique<FileOptionsProvider>(GlobalOptions, DefaultOptions,
300 OverrideOptions);
301}
302
Benjamin Kramere7103712015-03-23 12:49:15 +0000303static int clangTidyMain(int argc, const char **argv) {
Alexander Kornienko65eccb42015-08-17 10:03:27 +0000304 CommonOptionsParser OptionsParser(argc, argv, ClangTidyCategory,
305 cl::ZeroOrMore);
Alexander Kornienkoeff4e922014-09-26 11:42:29 +0000306
307 auto OptionsProvider = createOptionsProvider();
308 if (!OptionsProvider)
309 return 1;
Alexander Kornienkod53d2682014-09-04 14:23:36 +0000310
Alexander Kornienko65eccb42015-08-17 10:03:27 +0000311 StringRef FileName("dummy");
312 auto PathList = OptionsParser.getSourcePathList();
313 if (!PathList.empty()) {
Alexander Kornienkoe0c900e2015-08-17 11:27:11 +0000314 FileName = PathList.front();
Alexander Kornienko65eccb42015-08-17 10:03:27 +0000315 }
Haojian Wud1218752016-07-11 07:47:04 +0000316
317 SmallString<256> FilePath(FileName);
318 if (std::error_code EC = llvm::sys::fs::make_absolute(FilePath)) {
319 llvm::errs() << "Can't make absolute path from " << FileName << ": "
320 << EC.message() << "\n";
321 }
322 ClangTidyOptions EffectiveOptions = OptionsProvider->getOptions(FilePath);
Alexander Kornienkoc28c32d2014-09-10 11:43:09 +0000323 std::vector<std::string> EnabledChecks = getCheckNames(EffectiveOptions);
Alexander Kornienkofbf92582014-06-02 20:32:06 +0000324
Haojian Wu12e6b8f2016-04-27 09:15:01 +0000325 if (ExplainConfig) {
326 //FIXME: Show other ClangTidyOptions' fields, like ExtraArg.
327 std::vector<clang::tidy::ClangTidyOptionsProvider::OptionsSource>
Haojian Wud1218752016-07-11 07:47:04 +0000328 RawOptions = OptionsProvider->getRawOptions(FilePath);
Haojian Wu12e6b8f2016-04-27 09:15:01 +0000329 for (const std::string &Check : EnabledChecks) {
330 for (auto It = RawOptions.rbegin(); It != RawOptions.rend(); ++It) {
331 if (It->first.Checks && GlobList(*It->first.Checks).contains(Check)) {
332 llvm::outs() << "'" << Check << "' is enabled in the " << It->second
333 << ".\n";
334 break;
335 }
336 }
337 }
338 return 0;
339 }
340
Alexander Kornienkofb9e92b2013-12-19 19:57:05 +0000341 if (ListChecks) {
Alexander Kornienko493db092016-04-27 11:45:14 +0000342 if (EnabledChecks.empty()) {
343 llvm::errs() << "No checks enabled.\n";
344 return 1;
345 }
Alexander Kornienkofb9e92b2013-12-19 19:57:05 +0000346 llvm::outs() << "Enabled checks:";
Benjamin Kramer51a9cc92016-06-15 15:46:10 +0000347 for (const auto &CheckName : EnabledChecks)
Alexander Kornienko16ac6ce2014-03-05 13:14:32 +0000348 llvm::outs() << "\n " << CheckName;
Alexander Kornienkofb9e92b2013-12-19 19:57:05 +0000349 llvm::outs() << "\n\n";
350 return 0;
351 }
352
Alexander Kornienkod53d2682014-09-04 14:23:36 +0000353 if (DumpConfig) {
Alexander Kornienko6e0cbc82014-09-12 08:53:36 +0000354 EffectiveOptions.CheckOptions = getCheckOptions(EffectiveOptions);
Alexander Kornienko65eccb42015-08-17 10:03:27 +0000355 llvm::outs() << configurationAsText(
356 ClangTidyOptions::getDefaults().mergeWith(
357 EffectiveOptions))
Alexander Kornienkod53d2682014-09-04 14:23:36 +0000358 << "\n";
359 return 0;
360 }
361
Alexander Kornienkofbf92582014-06-02 20:32:06 +0000362 if (EnabledChecks.empty()) {
363 llvm::errs() << "Error: no checks enabled.\n";
364 llvm::cl::PrintHelpMessage(/*Hidden=*/false, /*Categorized=*/true);
365 return 1;
366 }
367
Alexander Kornienko65eccb42015-08-17 10:03:27 +0000368 if (PathList.empty()) {
369 llvm::errs() << "Error: no input files specified.\n";
370 llvm::cl::PrintHelpMessage(/*Hidden=*/false, /*Categorized=*/true);
371 return 1;
372 }
373
Samuel Benzaquenaedd9942014-10-23 17:23:20 +0000374 ProfileData Profile;
375
Alexander Kornienkoc28c32d2014-09-10 11:43:09 +0000376 std::vector<ClangTidyError> Errors;
377 ClangTidyStats Stats =
378 runClangTidy(std::move(OptionsProvider), OptionsParser.getCompilations(),
Alexander Kornienko65eccb42015-08-17 10:03:27 +0000379 PathList, &Errors,
Samuel Benzaquenaedd9942014-10-23 17:23:20 +0000380 EnableCheckProfile ? &Profile : nullptr);
Alexander Kornienko5eac3c62014-11-03 14:06:31 +0000381 bool FoundErrors =
382 std::find_if(Errors.begin(), Errors.end(), [](const ClangTidyError &E) {
383 return E.DiagLevel == ClangTidyError::Error;
384 }) != Errors.end();
385
386 const bool DisableFixes = Fix && FoundErrors && !FixErrors;
387
Jonathan Roelofsd60388a2016-01-13 17:36:41 +0000388 unsigned WErrorCount = 0;
389
Alexander Kornienko5eac3c62014-11-03 14:06:31 +0000390 // -fix-errors implies -fix.
Jonathan Roelofsd60388a2016-01-13 17:36:41 +0000391 handleErrors(Errors, (FixErrors || Fix) && !DisableFixes, WErrorCount);
Daniel Jasperd07c8402013-07-29 08:19:24 +0000392
Alexander Kornienko4153da22014-09-04 15:19:49 +0000393 if (!ExportFixes.empty() && !Errors.empty()) {
Benjamin Kramerfb98b742014-09-04 10:31:23 +0000394 std::error_code EC;
395 llvm::raw_fd_ostream OS(ExportFixes, EC, llvm::sys::fs::F_None);
396 if (EC) {
397 llvm::errs() << "Error opening output file: " << EC.message() << '\n';
398 return 1;
399 }
Alexander Kornienkoc28c32d2014-09-10 11:43:09 +0000400 exportReplacements(Errors, OS);
Benjamin Kramerfb98b742014-09-04 10:31:23 +0000401 }
402
Alexander Kornienko5d174542014-05-07 09:06:53 +0000403 printStats(Stats);
Alexander Kornienko5eac3c62014-11-03 14:06:31 +0000404 if (DisableFixes)
Alexander Kornienkob0a9b702014-12-09 15:02:17 +0000405 llvm::errs()
406 << "Found compiler errors, but -fix-errors was not specified.\n"
407 "Fixes have NOT been applied.\n\n";
Alexander Kornienko5eac3c62014-11-03 14:06:31 +0000408
Samuel Benzaquenaedd9942014-10-23 17:23:20 +0000409 if (EnableCheckProfile)
410 printProfileData(Profile, llvm::errs());
411
Jonathan Roelofsd60388a2016-01-13 17:36:41 +0000412 if (WErrorCount) {
413 StringRef Plural = WErrorCount == 1 ? "" : "s";
414 llvm::errs() << WErrorCount << " warning" << Plural << " treated as error"
415 << Plural << "\n";
416 return WErrorCount;
417 }
418
Daniel Jasperd07c8402013-07-29 08:19:24 +0000419 return 0;
420}
Daniel Jasper89bbab02013-08-04 15:56:30 +0000421
Aaron Ballmanea2f90c2015-10-02 13:27:19 +0000422// This anchor is used to force the linker to link the CERTModule.
423extern volatile int CERTModuleAnchorSource;
424static int LLVM_ATTRIBUTE_UNUSED CERTModuleAnchorDestination =
425 CERTModuleAnchorSource;
426
Piotr Padlewski5625f652016-04-29 17:58:29 +0000427// This anchor is used to force the linker to link the BoostModule.
428extern volatile int BoostModuleAnchorSource;
429static int LLVM_ATTRIBUTE_UNUSED BoostModuleAnchorDestination =
430 BoostModuleAnchorSource;
431
Daniel Jasper89bbab02013-08-04 15:56:30 +0000432// This anchor is used to force the linker to link the LLVMModule.
433extern volatile int LLVMModuleAnchorSource;
Alexander Kornienkoe1292f82015-08-19 16:54:51 +0000434static int LLVM_ATTRIBUTE_UNUSED LLVMModuleAnchorDestination =
435 LLVMModuleAnchorSource;
Daniel Jasper89bbab02013-08-04 15:56:30 +0000436
Aaron Ballmanaaa40802015-10-06 13:31:00 +0000437// This anchor is used to force the linker to link the CppCoreGuidelinesModule.
438extern volatile int CppCoreGuidelinesModuleAnchorSource;
439static int LLVM_ATTRIBUTE_UNUSED CppCoreGuidelinesModuleAnchorDestination =
440 CppCoreGuidelinesModuleAnchorSource;
441
Daniel Jasper89bbab02013-08-04 15:56:30 +0000442// This anchor is used to force the linker to link the GoogleModule.
443extern volatile int GoogleModuleAnchorSource;
Alexander Kornienkoe1292f82015-08-19 16:54:51 +0000444static int LLVM_ATTRIBUTE_UNUSED GoogleModuleAnchorDestination =
445 GoogleModuleAnchorSource;
Daniel Jasper89bbab02013-08-04 15:56:30 +0000446
Alexander Kornienko16ac6ce2014-03-05 13:14:32 +0000447// This anchor is used to force the linker to link the MiscModule.
448extern volatile int MiscModuleAnchorSource;
Alexander Kornienkoe1292f82015-08-19 16:54:51 +0000449static int LLVM_ATTRIBUTE_UNUSED MiscModuleAnchorDestination =
450 MiscModuleAnchorSource;
Alexander Kornienko16ac6ce2014-03-05 13:14:32 +0000451
Alexander Kornienkofc650862015-08-14 13:17:11 +0000452// This anchor is used to force the linker to link the ModernizeModule.
453extern volatile int ModernizeModuleAnchorSource;
Alexander Kornienkoe1292f82015-08-19 16:54:51 +0000454static int LLVM_ATTRIBUTE_UNUSED ModernizeModuleAnchorDestination =
455 ModernizeModuleAnchorSource;
Alexander Kornienkofc650862015-08-14 13:17:11 +0000456
Alexander Kornienko5e0a50c2016-08-02 20:29:35 +0000457// This anchor is used to force the linker to link the MPIModule.
458extern volatile int MPIModuleAnchorSource;
459static int LLVM_ATTRIBUTE_UNUSED MPIModuleAnchorDestination =
460 MPIModuleAnchorSource;
461
Alexander Kornienkob959f4c2015-12-30 10:24:40 +0000462// This anchor is used to force the linker to link the PerformanceModule.
463extern volatile int PerformanceModuleAnchorSource;
464static int LLVM_ATTRIBUTE_UNUSED PerformanceModuleAnchorDestination =
465 PerformanceModuleAnchorSource;
466
Alexander Kornienko2192a8e2014-10-26 01:41:14 +0000467// This anchor is used to force the linker to link the ReadabilityModule.
468extern volatile int ReadabilityModuleAnchorSource;
Alexander Kornienkoe1292f82015-08-19 16:54:51 +0000469static int LLVM_ATTRIBUTE_UNUSED ReadabilityModuleAnchorDestination =
470 ReadabilityModuleAnchorSource;
Alexander Kornienko2192a8e2014-10-26 01:41:14 +0000471
Daniel Jasper89bbab02013-08-04 15:56:30 +0000472} // namespace tidy
473} // namespace clang
Alexander Kornienkoc28c32d2014-09-10 11:43:09 +0000474
475int main(int argc, const char **argv) {
476 return clang::tidy::clangTidyMain(argc, argv);
477}