Daniel Jasper | d07c840 | 2013-07-29 08:19:24 +0000 | [diff] [blame] | 1 | //===--- 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 Klimek | 814f9bd | 2013-11-14 15:49:44 +0000 | [diff] [blame] | 19 | #include "clang/Tooling/CommonOptionsParser.h" |
Alexander Kornienko | e995154 | 2014-09-24 18:36:03 +0000 | [diff] [blame] | 20 | #include "llvm/Support/Process.h" |
Zachary Turner | fbdca1d | 2017-10-20 23:00:51 +0000 | [diff] [blame] | 21 | #include "llvm/Support/TargetSelect.h" |
Daniel Jasper | d07c840 | 2013-07-29 08:19:24 +0000 | [diff] [blame] | 22 | |
| 23 | using namespace clang::ast_matchers; |
| 24 | using namespace clang::driver; |
| 25 | using namespace clang::tooling; |
| 26 | using namespace llvm; |
| 27 | |
Alexander Kornienko | 99c9d6a | 2014-02-05 13:43:27 +0000 | [diff] [blame] | 28 | static cl::OptionCategory ClangTidyCategory("clang-tidy options"); |
Daniel Jasper | d07c840 | 2013-07-29 08:19:24 +0000 | [diff] [blame] | 29 | |
Manuel Klimek | 814f9bd | 2013-11-14 15:49:44 +0000 | [diff] [blame] | 30 | static cl::extrahelp CommonHelp(CommonOptionsParser::HelpMessage); |
Alexander Kornienko | f1d54eb | 2016-02-08 00:19:29 +0000 | [diff] [blame] | 31 | static cl::extrahelp ClangTidyHelp(R"( |
| 32 | Configuration files: |
| 33 | clang-tidy attempts to read configuration for each source file from a |
| 34 | .clang-tidy file located in the closest parent directory of the source |
| 35 | file. If any configuration options have a corresponding command-line |
| 36 | option, command-line option takes precedence. The effective |
| 37 | configuration can be inspected using -dump-config: |
| 38 | |
Alexander Kornienko | 215604c | 2017-04-06 14:27:00 +0000 | [diff] [blame] | 39 | $ clang-tidy -dump-config |
Alexander Kornienko | f1d54eb | 2016-02-08 00:19:29 +0000 | [diff] [blame] | 40 | --- |
| 41 | Checks: '-*,some-check' |
| 42 | WarningsAsErrors: '' |
| 43 | HeaderFilterRegex: '' |
| 44 | AnalyzeTemporaryDtors: false |
Alexander Kornienko | 215604c | 2017-04-06 14:27:00 +0000 | [diff] [blame] | 45 | FormatStyle: none |
Alexander Kornienko | f1d54eb | 2016-02-08 00:19:29 +0000 | [diff] [blame] | 46 | User: user |
| 47 | CheckOptions: |
| 48 | - key: some-check.SomeOption |
| 49 | value: 'some value' |
| 50 | ... |
| 51 | |
| 52 | )"); |
Daniel Jasper | d07c840 | 2013-07-29 08:19:24 +0000 | [diff] [blame] | 53 | |
Jonas Devlieghere | 7319184 | 2016-11-30 18:06:42 +0000 | [diff] [blame] | 54 | const char DefaultChecks[] = // Enable these checks by default: |
| 55 | "clang-diagnostic-*," // * compiler diagnostics |
| 56 | "clang-analyzer-*"; // * Static Analyzer checks |
Alexander Kornienko | dad4acb | 2014-05-22 16:07:11 +0000 | [diff] [blame] | 57 | |
Alexander Kornienko | f1d54eb | 2016-02-08 00:19:29 +0000 | [diff] [blame] | 58 | static cl::opt<std::string> Checks("checks", cl::desc(R"( |
| 59 | Comma-separated list of globs with optional '-' |
| 60 | prefix. Globs are processed in order of |
| 61 | appearance in the list. Globs without '-' |
| 62 | prefix add checks with matching names to the |
| 63 | set, globs with the '-' prefix remove checks |
| 64 | with matching names from the set of enabled |
Alexander Kornienko | 17a4b23 | 2017-03-03 11:16:34 +0000 | [diff] [blame] | 65 | checks. This option's value is appended to the |
Alexander Kornienko | f1d54eb | 2016-02-08 00:19:29 +0000 | [diff] [blame] | 66 | value of the 'Checks' option in .clang-tidy |
| 67 | file, if any. |
| 68 | )"), |
| 69 | cl::init(""), cl::cat(ClangTidyCategory)); |
Alexander Kornienko | dad4acb | 2014-05-22 16:07:11 +0000 | [diff] [blame] | 70 | |
Alexander Kornienko | f1d54eb | 2016-02-08 00:19:29 +0000 | [diff] [blame] | 71 | static cl::opt<std::string> WarningsAsErrors("warnings-as-errors", cl::desc(R"( |
| 72 | Upgrades warnings to errors. Same format as |
| 73 | '-checks'. |
| 74 | This option's value is appended to the value of |
| 75 | the 'WarningsAsErrors' option in .clang-tidy |
| 76 | file, if any. |
| 77 | )"), |
| 78 | cl::init(""), |
| 79 | cl::cat(ClangTidyCategory)); |
Jonathan Roelofs | d60388a | 2016-01-13 17:36:41 +0000 | [diff] [blame] | 80 | |
Alexander Kornienko | f1d54eb | 2016-02-08 00:19:29 +0000 | [diff] [blame] | 81 | static cl::opt<std::string> HeaderFilter("header-filter", cl::desc(R"( |
| 82 | Regular expression matching the names of the |
| 83 | headers to output diagnostics from. Diagnostics |
| 84 | from the main file of each translation unit are |
| 85 | always displayed. |
| 86 | Can be used together with -line-filter. |
| 87 | This option overrides the 'HeaderFilter' option |
| 88 | in .clang-tidy file, if any. |
| 89 | )"), |
| 90 | cl::init(""), |
| 91 | cl::cat(ClangTidyCategory)); |
Alexander Kornienko | dad4acb | 2014-05-22 16:07:11 +0000 | [diff] [blame] | 92 | |
Alexander Kornienko | 37f7abe | 2014-10-28 22:16:13 +0000 | [diff] [blame] | 93 | static cl::opt<bool> |
| 94 | SystemHeaders("system-headers", |
Alexander Kornienko | 5eac3c6 | 2014-11-03 14:06:31 +0000 | [diff] [blame] | 95 | cl::desc("Display the errors from system headers."), |
Alexander Kornienko | 37f7abe | 2014-10-28 22:16:13 +0000 | [diff] [blame] | 96 | cl::init(false), cl::cat(ClangTidyCategory)); |
Mandeep Singh Grang | 7c7ea7d | 2016-11-08 07:50:19 +0000 | [diff] [blame] | 97 | static cl::opt<std::string> LineFilter("line-filter", cl::desc(R"( |
Alexander Kornienko | f1d54eb | 2016-02-08 00:19:29 +0000 | [diff] [blame] | 98 | List of files with line ranges to filter the |
| 99 | warnings. Can be used together with |
| 100 | -header-filter. The format of the list is a |
| 101 | JSON array of objects: |
| 102 | [ |
| 103 | {"name":"file1.cpp","lines":[[1,3],[5,7]]}, |
| 104 | {"name":"file2.h"} |
| 105 | ] |
| 106 | )"), |
Mandeep Singh Grang | 7c7ea7d | 2016-11-08 07:50:19 +0000 | [diff] [blame] | 107 | cl::init(""), |
| 108 | cl::cat(ClangTidyCategory)); |
Alexander Kornienko | dad4acb | 2014-05-22 16:07:11 +0000 | [diff] [blame] | 109 | |
Alexander Kornienko | f1d54eb | 2016-02-08 00:19:29 +0000 | [diff] [blame] | 110 | static cl::opt<bool> Fix("fix", cl::desc(R"( |
| 111 | Apply suggested fixes. Without -fix-errors |
| 112 | clang-tidy will bail out if any compilation |
| 113 | errors were found. |
| 114 | )"), |
| 115 | cl::init(false), cl::cat(ClangTidyCategory)); |
Alexander Kornienko | 5eac3c6 | 2014-11-03 14:06:31 +0000 | [diff] [blame] | 116 | |
Alexander Kornienko | f1d54eb | 2016-02-08 00:19:29 +0000 | [diff] [blame] | 117 | static cl::opt<bool> FixErrors("fix-errors", cl::desc(R"( |
| 118 | Apply suggested fixes even if compilation |
| 119 | errors were found. If compiler errors have |
| 120 | attached fix-its, clang-tidy will apply them as |
| 121 | well. |
| 122 | )"), |
| 123 | cl::init(false), cl::cat(ClangTidyCategory)); |
Daniel Jasper | d07c840 | 2013-07-29 08:19:24 +0000 | [diff] [blame] | 124 | |
Alexander Kornienko | 17a4b23 | 2017-03-03 11:16:34 +0000 | [diff] [blame] | 125 | static cl::opt<std::string> FormatStyle("format-style", cl::desc(R"( |
| 126 | Style for formatting code around applied fixes: |
| 127 | - 'none' (default) turns off formatting |
| 128 | - 'file' (literally 'file', not a placeholder) |
| 129 | uses .clang-format file in the closest parent |
| 130 | directory |
| 131 | - '{ <json> }' specifies options inline, e.g. |
| 132 | -format-style='{BasedOnStyle: llvm, IndentWidth: 8}' |
| 133 | - 'llvm', 'google', 'webkit', 'mozilla' |
| 134 | See clang-format documentation for the up-to-date |
| 135 | information about formatting styles and options. |
Alexander Kornienko | 215604c | 2017-04-06 14:27:00 +0000 | [diff] [blame] | 136 | This option overrides the 'FormatStyle` option in |
| 137 | .clang-tidy file, if any. |
Jonas Devlieghere | 7319184 | 2016-11-30 18:06:42 +0000 | [diff] [blame] | 138 | )"), |
Alexander Kornienko | 17a4b23 | 2017-03-03 11:16:34 +0000 | [diff] [blame] | 139 | cl::init("none"), |
| 140 | cl::cat(ClangTidyCategory)); |
Jonas Devlieghere | 7319184 | 2016-11-30 18:06:42 +0000 | [diff] [blame] | 141 | |
Alexander Kornienko | f1d54eb | 2016-02-08 00:19:29 +0000 | [diff] [blame] | 142 | static cl::opt<bool> ListChecks("list-checks", cl::desc(R"( |
| 143 | List all enabled checks and exit. Use with |
| 144 | -checks=* to list all available checks. |
| 145 | )"), |
| 146 | cl::init(false), cl::cat(ClangTidyCategory)); |
Daniel Jasper | d07c840 | 2013-07-29 08:19:24 +0000 | [diff] [blame] | 147 | |
Haojian Wu | 12e6b8f | 2016-04-27 09:15:01 +0000 | [diff] [blame] | 148 | static cl::opt<bool> ExplainConfig("explain-config", cl::desc(R"( |
Haojian Wu | e5555e2 | 2016-09-22 14:36:43 +0000 | [diff] [blame] | 149 | For each enabled check explains, where it is |
| 150 | enabled, i.e. in clang-tidy binary, command |
| 151 | line or a specific configuration file. |
Haojian Wu | 12e6b8f | 2016-04-27 09:15:01 +0000 | [diff] [blame] | 152 | )"), |
| 153 | cl::init(false), cl::cat(ClangTidyCategory)); |
| 154 | |
Alexander Kornienko | f1d54eb | 2016-02-08 00:19:29 +0000 | [diff] [blame] | 155 | static cl::opt<std::string> Config("config", cl::desc(R"( |
| 156 | Specifies a configuration in YAML/JSON format: |
| 157 | -config="{Checks: '*', |
| 158 | CheckOptions: [{key: x, |
| 159 | value: y}]}" |
| 160 | When the value is empty, clang-tidy will |
| 161 | attempt to find a file named .clang-tidy for |
| 162 | each source file in its parent directories. |
| 163 | )"), |
| 164 | cl::init(""), cl::cat(ClangTidyCategory)); |
Alexander Kornienko | eff4e92 | 2014-09-26 11:42:29 +0000 | [diff] [blame] | 165 | |
Alexander Kornienko | f1d54eb | 2016-02-08 00:19:29 +0000 | [diff] [blame] | 166 | static cl::opt<bool> DumpConfig("dump-config", cl::desc(R"( |
| 167 | Dumps configuration in the YAML format to |
| 168 | stdout. This option can be used along with a |
| 169 | file name (and '--' if the file is outside of a |
| 170 | project with configured compilation database). |
| 171 | The configuration used for this file will be |
| 172 | printed. |
| 173 | Use along with -checks=* to include |
| 174 | configuration of all checks. |
| 175 | )"), |
| 176 | cl::init(false), cl::cat(ClangTidyCategory)); |
Alexander Kornienko | d53d268 | 2014-09-04 14:23:36 +0000 | [diff] [blame] | 177 | |
Alexander Kornienko | f1d54eb | 2016-02-08 00:19:29 +0000 | [diff] [blame] | 178 | static cl::opt<bool> EnableCheckProfile("enable-check-profile", cl::desc(R"( |
| 179 | Enable per-check timing profiles, and print a |
| 180 | report to stderr. |
| 181 | )"), |
| 182 | cl::init(false), |
| 183 | cl::cat(ClangTidyCategory)); |
Samuel Benzaquen | aedd994 | 2014-10-23 17:23:20 +0000 | [diff] [blame] | 184 | |
Alexander Kornienko | f1d54eb | 2016-02-08 00:19:29 +0000 | [diff] [blame] | 185 | static cl::opt<bool> AnalyzeTemporaryDtors("analyze-temporary-dtors", |
| 186 | cl::desc(R"( |
| 187 | Enable temporary destructor-aware analysis in |
| 188 | clang-analyzer- checks. |
| 189 | This option overrides the value read from a |
| 190 | .clang-tidy file. |
| 191 | )"), |
| 192 | cl::init(false), |
| 193 | cl::cat(ClangTidyCategory)); |
Alex McCarthy | fec08c7 | 2014-04-30 14:09:24 +0000 | [diff] [blame] | 194 | |
Alexander Kornienko | f1d54eb | 2016-02-08 00:19:29 +0000 | [diff] [blame] | 195 | static cl::opt<std::string> ExportFixes("export-fixes", cl::desc(R"( |
| 196 | YAML file to store suggested fixes in. The |
Kirill Bobyrev | 405699e | 2016-08-19 09:36:14 +0000 | [diff] [blame] | 197 | stored fixes can be applied to the input source |
Alexander Kornienko | f1d54eb | 2016-02-08 00:19:29 +0000 | [diff] [blame] | 198 | code with clang-apply-replacements. |
| 199 | )"), |
| 200 | cl::value_desc("filename"), |
| 201 | cl::cat(ClangTidyCategory)); |
Benjamin Kramer | fb98b74 | 2014-09-04 10:31:23 +0000 | [diff] [blame] | 202 | |
Ehsan Akhgari | b7418d3 | 2017-02-09 18:32:02 +0000 | [diff] [blame] | 203 | static cl::opt<bool> Quiet("quiet", cl::desc(R"( |
Alexander Kornienko | 17a4b23 | 2017-03-03 11:16:34 +0000 | [diff] [blame] | 204 | Run clang-tidy in quiet mode. This suppresses |
Ehsan Akhgari | b7418d3 | 2017-02-09 18:32:02 +0000 | [diff] [blame] | 205 | printing statistics about ignored warnings and |
| 206 | warnings treated as errors if the respective |
| 207 | options are specified. |
| 208 | )"), |
| 209 | cl::init(false), |
| 210 | cl::cat(ClangTidyCategory)); |
| 211 | |
Ilya Biryukov | a67b366 | 2018-01-23 12:31:06 +0000 | [diff] [blame] | 212 | static cl::opt<std::string> VfsOverlay("vfsoverlay", cl::desc(R"( |
| 213 | Overlay the virtual filesystem described by file |
| 214 | over the real file system. |
| 215 | )"), |
| 216 | cl::value_desc("filename"), |
| 217 | cl::cat(ClangTidyCategory)); |
| 218 | |
Alexander Kornienko | c28c32d | 2014-09-10 11:43:09 +0000 | [diff] [blame] | 219 | namespace clang { |
| 220 | namespace tidy { |
| 221 | |
| 222 | static void printStats(const ClangTidyStats &Stats) { |
Alexander Kornienko | dad4acb | 2014-05-22 16:07:11 +0000 | [diff] [blame] | 223 | if (Stats.errorsIgnored()) { |
| 224 | llvm::errs() << "Suppressed " << Stats.errorsIgnored() << " warnings ("; |
Alexander Kornienko | 5d17454 | 2014-05-07 09:06:53 +0000 | [diff] [blame] | 225 | StringRef Separator = ""; |
| 226 | if (Stats.ErrorsIgnoredNonUserCode) { |
| 227 | llvm::errs() << Stats.ErrorsIgnoredNonUserCode << " in non-user code"; |
| 228 | Separator = ", "; |
| 229 | } |
Alexander Kornienko | dad4acb | 2014-05-22 16:07:11 +0000 | [diff] [blame] | 230 | if (Stats.ErrorsIgnoredLineFilter) { |
| 231 | llvm::errs() << Separator << Stats.ErrorsIgnoredLineFilter |
| 232 | << " due to line filter"; |
| 233 | Separator = ", "; |
| 234 | } |
Alexander Kornienko | 5d17454 | 2014-05-07 09:06:53 +0000 | [diff] [blame] | 235 | if (Stats.ErrorsIgnoredNOLINT) { |
| 236 | llvm::errs() << Separator << Stats.ErrorsIgnoredNOLINT << " NOLINT"; |
| 237 | Separator = ", "; |
| 238 | } |
| 239 | if (Stats.ErrorsIgnoredCheckFilter) |
| 240 | llvm::errs() << Separator << Stats.ErrorsIgnoredCheckFilter |
| 241 | << " with check filters"; |
| 242 | llvm::errs() << ").\n"; |
| 243 | if (Stats.ErrorsIgnoredNonUserCode) |
Aaron Ballman | 5a4892b | 2015-07-27 13:41:30 +0000 | [diff] [blame] | 244 | llvm::errs() << "Use -header-filter=.* to display errors from all " |
Alexander Kornienko | f1d54eb | 2016-02-08 00:19:29 +0000 | [diff] [blame] | 245 | "non-system headers. Use -system-headers to display " |
| 246 | "errors from system headers as well.\n"; |
Alexander Kornienko | 5d17454 | 2014-05-07 09:06:53 +0000 | [diff] [blame] | 247 | } |
| 248 | } |
| 249 | |
Samuel Benzaquen | aedd994 | 2014-10-23 17:23:20 +0000 | [diff] [blame] | 250 | static void printProfileData(const ProfileData &Profile, |
| 251 | llvm::raw_ostream &OS) { |
| 252 | // Time is first to allow for sorting by it. |
| 253 | std::vector<std::pair<llvm::TimeRecord, StringRef>> Timers; |
| 254 | TimeRecord Total; |
| 255 | |
Mandeep Singh Grang | 7c7ea7d | 2016-11-08 07:50:19 +0000 | [diff] [blame] | 256 | for (const auto &P : Profile.Records) { |
Samuel Benzaquen | aedd994 | 2014-10-23 17:23:20 +0000 | [diff] [blame] | 257 | Timers.emplace_back(P.getValue(), P.getKey()); |
| 258 | Total += P.getValue(); |
| 259 | } |
| 260 | |
| 261 | std::sort(Timers.begin(), Timers.end()); |
| 262 | |
| 263 | std::string Line = "===" + std::string(73, '-') + "===\n"; |
| 264 | OS << Line; |
| 265 | |
| 266 | if (Total.getUserTime()) |
| 267 | OS << " ---User Time---"; |
| 268 | if (Total.getSystemTime()) |
| 269 | OS << " --System Time--"; |
| 270 | if (Total.getProcessTime()) |
| 271 | OS << " --User+System--"; |
| 272 | OS << " ---Wall Time---"; |
| 273 | if (Total.getMemUsed()) |
| 274 | OS << " ---Mem---"; |
| 275 | OS << " --- Name ---\n"; |
| 276 | |
| 277 | // Loop through all of the timing data, printing it out. |
| 278 | for (auto I = Timers.rbegin(), E = Timers.rend(); I != E; ++I) { |
| 279 | I->first.print(Total, OS); |
| 280 | OS << I->second << '\n'; |
| 281 | } |
| 282 | |
| 283 | Total.print(Total, OS); |
| 284 | OS << "Total\n"; |
| 285 | OS << Line << "\n"; |
| 286 | OS.flush(); |
| 287 | } |
| 288 | |
Benjamin Kramer | e710371 | 2015-03-23 12:49:15 +0000 | [diff] [blame] | 289 | static std::unique_ptr<ClangTidyOptionsProvider> createOptionsProvider() { |
Alexander Kornienko | c28c32d | 2014-09-10 11:43:09 +0000 | [diff] [blame] | 290 | ClangTidyGlobalOptions GlobalOptions; |
| 291 | if (std::error_code Err = parseLineFilter(LineFilter, GlobalOptions)) { |
Alexander Kornienko | dad4acb | 2014-05-22 16:07:11 +0000 | [diff] [blame] | 292 | llvm::errs() << "Invalid LineFilter: " << Err.message() << "\n\nUsage:\n"; |
| 293 | llvm::cl::PrintHelpMessage(/*Hidden=*/false, /*Categorized=*/true); |
Alexander Kornienko | eff4e92 | 2014-09-26 11:42:29 +0000 | [diff] [blame] | 294 | return nullptr; |
Alexander Kornienko | dad4acb | 2014-05-22 16:07:11 +0000 | [diff] [blame] | 295 | } |
Alexander Kornienko | 33a9bcc | 2014-04-29 15:20:10 +0000 | [diff] [blame] | 296 | |
Alexander Kornienko | e995154 | 2014-09-24 18:36:03 +0000 | [diff] [blame] | 297 | ClangTidyOptions DefaultOptions; |
| 298 | DefaultOptions.Checks = DefaultChecks; |
Jonathan Roelofs | d60388a | 2016-01-13 17:36:41 +0000 | [diff] [blame] | 299 | DefaultOptions.WarningsAsErrors = ""; |
Alexander Kornienko | e995154 | 2014-09-24 18:36:03 +0000 | [diff] [blame] | 300 | DefaultOptions.HeaderFilterRegex = HeaderFilter; |
Alexander Kornienko | 37f7abe | 2014-10-28 22:16:13 +0000 | [diff] [blame] | 301 | DefaultOptions.SystemHeaders = SystemHeaders; |
Alexander Kornienko | e995154 | 2014-09-24 18:36:03 +0000 | [diff] [blame] | 302 | DefaultOptions.AnalyzeTemporaryDtors = AnalyzeTemporaryDtors; |
Alexander Kornienko | 2561320 | 2017-04-06 13:41:29 +0000 | [diff] [blame] | 303 | DefaultOptions.FormatStyle = FormatStyle; |
Alexander Kornienko | e995154 | 2014-09-24 18:36:03 +0000 | [diff] [blame] | 304 | DefaultOptions.User = llvm::sys::Process::GetEnv("USER"); |
| 305 | // USERNAME is used on Windows. |
| 306 | if (!DefaultOptions.User) |
| 307 | DefaultOptions.User = llvm::sys::Process::GetEnv("USERNAME"); |
Alexander Kornienko | a469522 | 2014-06-05 13:31:45 +0000 | [diff] [blame] | 308 | |
Alexander Kornienko | c28c32d | 2014-09-10 11:43:09 +0000 | [diff] [blame] | 309 | ClangTidyOptions OverrideOptions; |
Alexander Kornienko | d53d268 | 2014-09-04 14:23:36 +0000 | [diff] [blame] | 310 | if (Checks.getNumOccurrences() > 0) |
| 311 | OverrideOptions.Checks = Checks; |
Jonathan Roelofs | d60388a | 2016-01-13 17:36:41 +0000 | [diff] [blame] | 312 | if (WarningsAsErrors.getNumOccurrences() > 0) |
| 313 | OverrideOptions.WarningsAsErrors = WarningsAsErrors; |
Alexander Kornienko | d53d268 | 2014-09-04 14:23:36 +0000 | [diff] [blame] | 314 | if (HeaderFilter.getNumOccurrences() > 0) |
| 315 | OverrideOptions.HeaderFilterRegex = HeaderFilter; |
Alexander Kornienko | 37f7abe | 2014-10-28 22:16:13 +0000 | [diff] [blame] | 316 | if (SystemHeaders.getNumOccurrences() > 0) |
| 317 | OverrideOptions.SystemHeaders = SystemHeaders; |
Alexander Kornienko | d53d268 | 2014-09-04 14:23:36 +0000 | [diff] [blame] | 318 | if (AnalyzeTemporaryDtors.getNumOccurrences() > 0) |
| 319 | OverrideOptions.AnalyzeTemporaryDtors = AnalyzeTemporaryDtors; |
Alexander Kornienko | 2561320 | 2017-04-06 13:41:29 +0000 | [diff] [blame] | 320 | if (FormatStyle.getNumOccurrences() > 0) |
| 321 | OverrideOptions.FormatStyle = FormatStyle; |
Alexander Kornienko | d53d268 | 2014-09-04 14:23:36 +0000 | [diff] [blame] | 322 | |
Alexander Kornienko | eff4e92 | 2014-09-26 11:42:29 +0000 | [diff] [blame] | 323 | if (!Config.empty()) { |
| 324 | if (llvm::ErrorOr<ClangTidyOptions> ParsedConfig = |
| 325 | parseConfiguration(Config)) { |
Haojian Wu | 12e6b8f | 2016-04-27 09:15:01 +0000 | [diff] [blame] | 326 | return llvm::make_unique<ConfigOptionsProvider>( |
| 327 | GlobalOptions, |
| 328 | ClangTidyOptions::getDefaults().mergeWith(DefaultOptions), |
| 329 | *ParsedConfig, OverrideOptions); |
Alexander Kornienko | eff4e92 | 2014-09-26 11:42:29 +0000 | [diff] [blame] | 330 | } else { |
| 331 | llvm::errs() << "Error: invalid configuration specified.\n" |
| 332 | << ParsedConfig.getError().message() << "\n"; |
| 333 | return nullptr; |
| 334 | } |
| 335 | } |
| 336 | return llvm::make_unique<FileOptionsProvider>(GlobalOptions, DefaultOptions, |
| 337 | OverrideOptions); |
| 338 | } |
| 339 | |
Ilya Biryukov | a67b366 | 2018-01-23 12:31:06 +0000 | [diff] [blame] | 340 | llvm::IntrusiveRefCntPtr<vfs::FileSystem> |
| 341 | getVfsOverlayFromFile(const std::string &OverlayFile) { |
| 342 | llvm::IntrusiveRefCntPtr<vfs::OverlayFileSystem> OverlayFS( |
| 343 | new vfs::OverlayFileSystem(vfs::getRealFileSystem())); |
| 344 | llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> Buffer = |
| 345 | OverlayFS->getBufferForFile(OverlayFile); |
| 346 | if (!Buffer) { |
| 347 | llvm::errs() << "Can't load virtual filesystem overlay file '" |
| 348 | << OverlayFile << "': " << Buffer.getError().message() |
| 349 | << ".\n"; |
| 350 | return nullptr; |
| 351 | } |
| 352 | |
| 353 | IntrusiveRefCntPtr<vfs::FileSystem> FS = vfs::getVFSFromYAML( |
| 354 | std::move(Buffer.get()), /*DiagHandler*/ nullptr, OverlayFile); |
| 355 | if (!FS) { |
| 356 | llvm::errs() << "Error: invalid virtual filesystem overlay file '" |
| 357 | << OverlayFile << "'.\n"; |
| 358 | return nullptr; |
| 359 | } |
| 360 | OverlayFS->pushOverlay(FS); |
| 361 | return OverlayFS; |
| 362 | } |
| 363 | |
Benjamin Kramer | e710371 | 2015-03-23 12:49:15 +0000 | [diff] [blame] | 364 | static int clangTidyMain(int argc, const char **argv) { |
Alexander Kornienko | 65eccb4 | 2015-08-17 10:03:27 +0000 | [diff] [blame] | 365 | CommonOptionsParser OptionsParser(argc, argv, ClangTidyCategory, |
| 366 | cl::ZeroOrMore); |
Alexander Kornienko | eff4e92 | 2014-09-26 11:42:29 +0000 | [diff] [blame] | 367 | |
Alexander Kornienko | 2561320 | 2017-04-06 13:41:29 +0000 | [diff] [blame] | 368 | auto OwningOptionsProvider = createOptionsProvider(); |
| 369 | auto *OptionsProvider = OwningOptionsProvider.get(); |
Alexander Kornienko | eff4e92 | 2014-09-26 11:42:29 +0000 | [diff] [blame] | 370 | if (!OptionsProvider) |
| 371 | return 1; |
Alexander Kornienko | d53d268 | 2014-09-04 14:23:36 +0000 | [diff] [blame] | 372 | |
Alexander Kornienko | 65eccb4 | 2015-08-17 10:03:27 +0000 | [diff] [blame] | 373 | StringRef FileName("dummy"); |
| 374 | auto PathList = OptionsParser.getSourcePathList(); |
| 375 | if (!PathList.empty()) { |
Alexander Kornienko | e0c900e | 2015-08-17 11:27:11 +0000 | [diff] [blame] | 376 | FileName = PathList.front(); |
Alexander Kornienko | 65eccb4 | 2015-08-17 10:03:27 +0000 | [diff] [blame] | 377 | } |
Haojian Wu | d121875 | 2016-07-11 07:47:04 +0000 | [diff] [blame] | 378 | |
| 379 | SmallString<256> FilePath(FileName); |
| 380 | if (std::error_code EC = llvm::sys::fs::make_absolute(FilePath)) { |
| 381 | llvm::errs() << "Can't make absolute path from " << FileName << ": " |
| 382 | << EC.message() << "\n"; |
| 383 | } |
| 384 | ClangTidyOptions EffectiveOptions = OptionsProvider->getOptions(FilePath); |
Alexander Kornienko | c28c32d | 2014-09-10 11:43:09 +0000 | [diff] [blame] | 385 | std::vector<std::string> EnabledChecks = getCheckNames(EffectiveOptions); |
Alexander Kornienko | fbf9258 | 2014-06-02 20:32:06 +0000 | [diff] [blame] | 386 | |
Haojian Wu | 12e6b8f | 2016-04-27 09:15:01 +0000 | [diff] [blame] | 387 | if (ExplainConfig) { |
Mandeep Singh Grang | 7c7ea7d | 2016-11-08 07:50:19 +0000 | [diff] [blame] | 388 | // FIXME: Show other ClangTidyOptions' fields, like ExtraArg. |
Haojian Wu | 12e6b8f | 2016-04-27 09:15:01 +0000 | [diff] [blame] | 389 | std::vector<clang::tidy::ClangTidyOptionsProvider::OptionsSource> |
Haojian Wu | d121875 | 2016-07-11 07:47:04 +0000 | [diff] [blame] | 390 | RawOptions = OptionsProvider->getRawOptions(FilePath); |
Haojian Wu | 12e6b8f | 2016-04-27 09:15:01 +0000 | [diff] [blame] | 391 | for (const std::string &Check : EnabledChecks) { |
| 392 | for (auto It = RawOptions.rbegin(); It != RawOptions.rend(); ++It) { |
| 393 | if (It->first.Checks && GlobList(*It->first.Checks).contains(Check)) { |
| 394 | llvm::outs() << "'" << Check << "' is enabled in the " << It->second |
| 395 | << ".\n"; |
| 396 | break; |
| 397 | } |
| 398 | } |
| 399 | } |
| 400 | return 0; |
| 401 | } |
| 402 | |
Alexander Kornienko | fb9e92b | 2013-12-19 19:57:05 +0000 | [diff] [blame] | 403 | if (ListChecks) { |
Alexander Kornienko | 493db09 | 2016-04-27 11:45:14 +0000 | [diff] [blame] | 404 | if (EnabledChecks.empty()) { |
| 405 | llvm::errs() << "No checks enabled.\n"; |
| 406 | return 1; |
| 407 | } |
Alexander Kornienko | fb9e92b | 2013-12-19 19:57:05 +0000 | [diff] [blame] | 408 | llvm::outs() << "Enabled checks:"; |
Benjamin Kramer | 51a9cc9 | 2016-06-15 15:46:10 +0000 | [diff] [blame] | 409 | for (const auto &CheckName : EnabledChecks) |
Alexander Kornienko | 16ac6ce | 2014-03-05 13:14:32 +0000 | [diff] [blame] | 410 | llvm::outs() << "\n " << CheckName; |
Alexander Kornienko | fb9e92b | 2013-12-19 19:57:05 +0000 | [diff] [blame] | 411 | llvm::outs() << "\n\n"; |
| 412 | return 0; |
| 413 | } |
| 414 | |
Alexander Kornienko | d53d268 | 2014-09-04 14:23:36 +0000 | [diff] [blame] | 415 | if (DumpConfig) { |
Alexander Kornienko | 6e0cbc8 | 2014-09-12 08:53:36 +0000 | [diff] [blame] | 416 | EffectiveOptions.CheckOptions = getCheckOptions(EffectiveOptions); |
Alexander Kornienko | 65eccb4 | 2015-08-17 10:03:27 +0000 | [diff] [blame] | 417 | llvm::outs() << configurationAsText( |
| 418 | ClangTidyOptions::getDefaults().mergeWith( |
| 419 | EffectiveOptions)) |
Alexander Kornienko | d53d268 | 2014-09-04 14:23:36 +0000 | [diff] [blame] | 420 | << "\n"; |
| 421 | return 0; |
| 422 | } |
| 423 | |
Alexander Kornienko | fbf9258 | 2014-06-02 20:32:06 +0000 | [diff] [blame] | 424 | if (EnabledChecks.empty()) { |
| 425 | llvm::errs() << "Error: no checks enabled.\n"; |
| 426 | llvm::cl::PrintHelpMessage(/*Hidden=*/false, /*Categorized=*/true); |
Rafael Espindola | d63b2f3 | 2017-09-08 00:33:39 +0000 | [diff] [blame] | 427 | return 0; |
Alexander Kornienko | fbf9258 | 2014-06-02 20:32:06 +0000 | [diff] [blame] | 428 | } |
| 429 | |
Alexander Kornienko | 65eccb4 | 2015-08-17 10:03:27 +0000 | [diff] [blame] | 430 | if (PathList.empty()) { |
| 431 | llvm::errs() << "Error: no input files specified.\n"; |
| 432 | llvm::cl::PrintHelpMessage(/*Hidden=*/false, /*Categorized=*/true); |
Rafael Espindola | d63b2f3 | 2017-09-08 00:33:39 +0000 | [diff] [blame] | 433 | return 0; |
Alexander Kornienko | 65eccb4 | 2015-08-17 10:03:27 +0000 | [diff] [blame] | 434 | } |
Ilya Biryukov | a67b366 | 2018-01-23 12:31:06 +0000 | [diff] [blame] | 435 | llvm::IntrusiveRefCntPtr<vfs::FileSystem> BaseFS( |
| 436 | VfsOverlay.empty() ? vfs::getRealFileSystem() |
| 437 | : getVfsOverlayFromFile(VfsOverlay)); |
| 438 | if (!BaseFS) |
| 439 | return 1; |
Alexander Kornienko | 65eccb4 | 2015-08-17 10:03:27 +0000 | [diff] [blame] | 440 | |
Samuel Benzaquen | aedd994 | 2014-10-23 17:23:20 +0000 | [diff] [blame] | 441 | ProfileData Profile; |
| 442 | |
Zachary Turner | fbdca1d | 2017-10-20 23:00:51 +0000 | [diff] [blame] | 443 | llvm::InitializeAllTargetInfos(); |
| 444 | llvm::InitializeAllTargetMCs(); |
| 445 | llvm::InitializeAllAsmParsers(); |
| 446 | |
Alexander Kornienko | 2561320 | 2017-04-06 13:41:29 +0000 | [diff] [blame] | 447 | ClangTidyContext Context(std::move(OwningOptionsProvider)); |
Ilya Biryukov | a67b366 | 2018-01-23 12:31:06 +0000 | [diff] [blame] | 448 | runClangTidy(Context, OptionsParser.getCompilations(), PathList, BaseFS, |
Alexander Kornienko | 2561320 | 2017-04-06 13:41:29 +0000 | [diff] [blame] | 449 | EnableCheckProfile ? &Profile : nullptr); |
| 450 | ArrayRef<ClangTidyError> Errors = Context.getErrors(); |
Alexander Kornienko | 5eac3c6 | 2014-11-03 14:06:31 +0000 | [diff] [blame] | 451 | bool FoundErrors = |
| 452 | std::find_if(Errors.begin(), Errors.end(), [](const ClangTidyError &E) { |
| 453 | return E.DiagLevel == ClangTidyError::Error; |
| 454 | }) != Errors.end(); |
| 455 | |
| 456 | const bool DisableFixes = Fix && FoundErrors && !FixErrors; |
| 457 | |
Jonathan Roelofs | d60388a | 2016-01-13 17:36:41 +0000 | [diff] [blame] | 458 | unsigned WErrorCount = 0; |
| 459 | |
Alexander Kornienko | 5eac3c6 | 2014-11-03 14:06:31 +0000 | [diff] [blame] | 460 | // -fix-errors implies -fix. |
Ilya Biryukov | a67b366 | 2018-01-23 12:31:06 +0000 | [diff] [blame] | 461 | handleErrors(Context, (FixErrors || Fix) && !DisableFixes, WErrorCount, |
| 462 | BaseFS); |
Daniel Jasper | d07c840 | 2013-07-29 08:19:24 +0000 | [diff] [blame] | 463 | |
Alexander Kornienko | 4153da2 | 2014-09-04 15:19:49 +0000 | [diff] [blame] | 464 | if (!ExportFixes.empty() && !Errors.empty()) { |
Benjamin Kramer | fb98b74 | 2014-09-04 10:31:23 +0000 | [diff] [blame] | 465 | std::error_code EC; |
| 466 | llvm::raw_fd_ostream OS(ExportFixes, EC, llvm::sys::fs::F_None); |
| 467 | if (EC) { |
| 468 | llvm::errs() << "Error opening output file: " << EC.message() << '\n'; |
| 469 | return 1; |
| 470 | } |
Alexander Kornienko | 563de79 | 2017-01-03 14:36:13 +0000 | [diff] [blame] | 471 | exportReplacements(FilePath.str(), Errors, OS); |
Benjamin Kramer | fb98b74 | 2014-09-04 10:31:23 +0000 | [diff] [blame] | 472 | } |
| 473 | |
Ehsan Akhgari | b7418d3 | 2017-02-09 18:32:02 +0000 | [diff] [blame] | 474 | if (!Quiet) { |
Alexander Kornienko | 2561320 | 2017-04-06 13:41:29 +0000 | [diff] [blame] | 475 | printStats(Context.getStats()); |
Ehsan Akhgari | b7418d3 | 2017-02-09 18:32:02 +0000 | [diff] [blame] | 476 | if (DisableFixes) |
| 477 | llvm::errs() |
| 478 | << "Found compiler errors, but -fix-errors was not specified.\n" |
| 479 | "Fixes have NOT been applied.\n\n"; |
| 480 | } |
Alexander Kornienko | 5eac3c6 | 2014-11-03 14:06:31 +0000 | [diff] [blame] | 481 | |
Samuel Benzaquen | aedd994 | 2014-10-23 17:23:20 +0000 | [diff] [blame] | 482 | if (EnableCheckProfile) |
| 483 | printProfileData(Profile, llvm::errs()); |
| 484 | |
Jonathan Roelofs | d60388a | 2016-01-13 17:36:41 +0000 | [diff] [blame] | 485 | if (WErrorCount) { |
Ehsan Akhgari | b7418d3 | 2017-02-09 18:32:02 +0000 | [diff] [blame] | 486 | if (!Quiet) { |
| 487 | StringRef Plural = WErrorCount == 1 ? "" : "s"; |
| 488 | llvm::errs() << WErrorCount << " warning" << Plural << " treated as error" |
| 489 | << Plural << "\n"; |
| 490 | } |
Jonathan Roelofs | d60388a | 2016-01-13 17:36:41 +0000 | [diff] [blame] | 491 | return WErrorCount; |
| 492 | } |
| 493 | |
Daniel Jasper | d07c840 | 2013-07-29 08:19:24 +0000 | [diff] [blame] | 494 | return 0; |
| 495 | } |
Daniel Jasper | 89bbab0 | 2013-08-04 15:56:30 +0000 | [diff] [blame] | 496 | |
Aaron Ballman | ea2f90c | 2015-10-02 13:27:19 +0000 | [diff] [blame] | 497 | // This anchor is used to force the linker to link the CERTModule. |
| 498 | extern volatile int CERTModuleAnchorSource; |
| 499 | static int LLVM_ATTRIBUTE_UNUSED CERTModuleAnchorDestination = |
| 500 | CERTModuleAnchorSource; |
| 501 | |
Haojian Wu | 40571b7c | 2018-03-09 10:47:14 +0000 | [diff] [blame] | 502 | // This anchor is used to force the linker to link the AbseilModule. |
| 503 | extern volatile int AbseilModuleAnchorSource; |
| 504 | static int LLVM_ATTRIBUTE_UNUSED AbseilModuleAnchorDestination = |
| 505 | AbseilModuleAnchorSource; |
| 506 | |
Piotr Padlewski | 5625f65 | 2016-04-29 17:58:29 +0000 | [diff] [blame] | 507 | // This anchor is used to force the linker to link the BoostModule. |
| 508 | extern volatile int BoostModuleAnchorSource; |
| 509 | static int LLVM_ATTRIBUTE_UNUSED BoostModuleAnchorDestination = |
| 510 | BoostModuleAnchorSource; |
| 511 | |
Gabor Horvath | 829e75a | 2017-07-14 12:15:55 +0000 | [diff] [blame] | 512 | // This anchor is used to force the linker to link the BugproneModule. |
| 513 | extern volatile int BugproneModuleAnchorSource; |
| 514 | static int LLVM_ATTRIBUTE_UNUSED BugproneModuleAnchorDestination = |
| 515 | BugproneModuleAnchorSource; |
| 516 | |
Daniel Jasper | 89bbab0 | 2013-08-04 15:56:30 +0000 | [diff] [blame] | 517 | // This anchor is used to force the linker to link the LLVMModule. |
| 518 | extern volatile int LLVMModuleAnchorSource; |
Alexander Kornienko | e1292f8 | 2015-08-19 16:54:51 +0000 | [diff] [blame] | 519 | static int LLVM_ATTRIBUTE_UNUSED LLVMModuleAnchorDestination = |
| 520 | LLVMModuleAnchorSource; |
Daniel Jasper | 89bbab0 | 2013-08-04 15:56:30 +0000 | [diff] [blame] | 521 | |
Aaron Ballman | aaa4080 | 2015-10-06 13:31:00 +0000 | [diff] [blame] | 522 | // This anchor is used to force the linker to link the CppCoreGuidelinesModule. |
| 523 | extern volatile int CppCoreGuidelinesModuleAnchorSource; |
| 524 | static int LLVM_ATTRIBUTE_UNUSED CppCoreGuidelinesModuleAnchorDestination = |
| 525 | CppCoreGuidelinesModuleAnchorSource; |
| 526 | |
Julie Hockett | c12d753 | 2018-03-13 21:24:08 +0000 | [diff] [blame] | 527 | // This anchor is used to force the linker to link the FuchsiaModule. |
Aaron Ballman | d3d78b9 | 2017-11-28 21:09:25 +0000 | [diff] [blame] | 528 | extern volatile int FuchsiaModuleAnchorSource; |
| 529 | static int LLVM_ATTRIBUTE_UNUSED FuchsiaModuleAnchorDestination = |
| 530 | FuchsiaModuleAnchorSource; |
| 531 | |
| 532 | // This anchor is used to force the linker to link the GoogleModule. |
Daniel Jasper | 89bbab0 | 2013-08-04 15:56:30 +0000 | [diff] [blame] | 533 | extern volatile int GoogleModuleAnchorSource; |
Alexander Kornienko | e1292f8 | 2015-08-19 16:54:51 +0000 | [diff] [blame] | 534 | static int LLVM_ATTRIBUTE_UNUSED GoogleModuleAnchorDestination = |
| 535 | GoogleModuleAnchorSource; |
Daniel Jasper | 89bbab0 | 2013-08-04 15:56:30 +0000 | [diff] [blame] | 536 | |
Yan Wang | 3620620 | 2017-06-23 21:37:29 +0000 | [diff] [blame] | 537 | // This anchor is used to force the linker to link the AndroidModule. |
| 538 | extern volatile int AndroidModuleAnchorSource; |
| 539 | static int LLVM_ATTRIBUTE_UNUSED AndroidModuleAnchorDestination = |
| 540 | AndroidModuleAnchorSource; |
| 541 | |
Alexander Kornienko | 16ac6ce | 2014-03-05 13:14:32 +0000 | [diff] [blame] | 542 | // This anchor is used to force the linker to link the MiscModule. |
| 543 | extern volatile int MiscModuleAnchorSource; |
Alexander Kornienko | e1292f8 | 2015-08-19 16:54:51 +0000 | [diff] [blame] | 544 | static int LLVM_ATTRIBUTE_UNUSED MiscModuleAnchorDestination = |
| 545 | MiscModuleAnchorSource; |
Alexander Kornienko | 16ac6ce | 2014-03-05 13:14:32 +0000 | [diff] [blame] | 546 | |
Alexander Kornienko | fc65086 | 2015-08-14 13:17:11 +0000 | [diff] [blame] | 547 | // This anchor is used to force the linker to link the ModernizeModule. |
| 548 | extern volatile int ModernizeModuleAnchorSource; |
Alexander Kornienko | e1292f8 | 2015-08-19 16:54:51 +0000 | [diff] [blame] | 549 | static int LLVM_ATTRIBUTE_UNUSED ModernizeModuleAnchorDestination = |
| 550 | ModernizeModuleAnchorSource; |
Alexander Kornienko | fc65086 | 2015-08-14 13:17:11 +0000 | [diff] [blame] | 551 | |
Alexander Kornienko | 5e0a50c | 2016-08-02 20:29:35 +0000 | [diff] [blame] | 552 | // This anchor is used to force the linker to link the MPIModule. |
| 553 | extern volatile int MPIModuleAnchorSource; |
| 554 | static int LLVM_ATTRIBUTE_UNUSED MPIModuleAnchorDestination = |
Mandeep Singh Grang | 7c7ea7d | 2016-11-08 07:50:19 +0000 | [diff] [blame] | 555 | MPIModuleAnchorSource; |
Alexander Kornienko | 5e0a50c | 2016-08-02 20:29:35 +0000 | [diff] [blame] | 556 | |
Alexander Kornienko | b959f4c | 2015-12-30 10:24:40 +0000 | [diff] [blame] | 557 | // This anchor is used to force the linker to link the PerformanceModule. |
| 558 | extern volatile int PerformanceModuleAnchorSource; |
| 559 | static int LLVM_ATTRIBUTE_UNUSED PerformanceModuleAnchorDestination = |
| 560 | PerformanceModuleAnchorSource; |
| 561 | |
Fangrui Song | c0e768d | 2018-03-07 16:57:42 +0000 | [diff] [blame] | 562 | // This anchor is used to force the linker to link the PortabilityModule. |
| 563 | extern volatile int PortabilityModuleAnchorSource; |
| 564 | static int LLVM_ATTRIBUTE_UNUSED PortabilityModuleAnchorDestination = |
| 565 | PortabilityModuleAnchorSource; |
| 566 | |
Alexander Kornienko | 2192a8e | 2014-10-26 01:41:14 +0000 | [diff] [blame] | 567 | // This anchor is used to force the linker to link the ReadabilityModule. |
| 568 | extern volatile int ReadabilityModuleAnchorSource; |
Alexander Kornienko | e1292f8 | 2015-08-19 16:54:51 +0000 | [diff] [blame] | 569 | static int LLVM_ATTRIBUTE_UNUSED ReadabilityModuleAnchorDestination = |
| 570 | ReadabilityModuleAnchorSource; |
Alexander Kornienko | 2192a8e | 2014-10-26 01:41:14 +0000 | [diff] [blame] | 571 | |
Haojian Wu | abcd64c | 2017-10-26 08:23:20 +0000 | [diff] [blame] | 572 | // This anchor is used to force the linker to link the ObjCModule. |
| 573 | extern volatile int ObjCModuleAnchorSource; |
| 574 | static int LLVM_ATTRIBUTE_UNUSED ObjCModuleAnchorDestination = |
| 575 | ObjCModuleAnchorSource; |
| 576 | |
Aaron Ballman | dbdbabf | 2017-03-19 17:23:23 +0000 | [diff] [blame] | 577 | // This anchor is used to force the linker to link the HICPPModule. |
| 578 | extern volatile int HICPPModuleAnchorSource; |
| 579 | static int LLVM_ATTRIBUTE_UNUSED HICPPModuleAnchorDestination = |
| 580 | HICPPModuleAnchorSource; |
Jonathan Coe | 3032d3c | 2017-02-06 22:57:14 +0000 | [diff] [blame] | 581 | |
Daniel Jasper | 89bbab0 | 2013-08-04 15:56:30 +0000 | [diff] [blame] | 582 | } // namespace tidy |
| 583 | } // namespace clang |
Alexander Kornienko | c28c32d | 2014-09-10 11:43:09 +0000 | [diff] [blame] | 584 | |
| 585 | int main(int argc, const char **argv) { |
| 586 | return clang::tidy::clangTidyMain(argc, argv); |
| 587 | } |