driver.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515
  1. //===-- driver.cpp - Clang GCC-Compatible Driver --------------------------===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. //
  9. // This is the entry point to the clang driver; it is a thin wrapper
  10. // for functionality in the Driver clang library.
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #include "clang/Driver/Driver.h"
  14. #include "clang/Basic/DiagnosticOptions.h"
  15. #include "clang/Basic/Stack.h"
  16. #include "clang/Driver/Compilation.h"
  17. #include "clang/Driver/DriverDiagnostic.h"
  18. #include "clang/Driver/Options.h"
  19. #include "clang/Driver/ToolChain.h"
  20. #include "clang/Frontend/ChainedDiagnosticConsumer.h"
  21. #include "clang/Frontend/CompilerInvocation.h"
  22. #include "clang/Frontend/SerializedDiagnosticPrinter.h"
  23. #include "clang/Frontend/TextDiagnosticPrinter.h"
  24. #include "clang/Frontend/Utils.h"
  25. #include "llvm/ADT/ArrayRef.h"
  26. #include "llvm/ADT/SmallString.h"
  27. #include "llvm/ADT/SmallVector.h"
  28. #include "llvm/Option/ArgList.h"
  29. #include "llvm/Option/OptTable.h"
  30. #include "llvm/Option/Option.h"
  31. #include "llvm/Support/CommandLine.h"
  32. #include "llvm/Support/ErrorHandling.h"
  33. #include "llvm/Support/FileSystem.h"
  34. #include "llvm/Support/Host.h"
  35. #include "llvm/Support/InitLLVM.h"
  36. #include "llvm/Support/Path.h"
  37. #include "llvm/Support/Process.h"
  38. #include "llvm/Support/Program.h"
  39. #include "llvm/Support/Regex.h"
  40. #include "llvm/Support/Signals.h"
  41. #include "llvm/Support/StringSaver.h"
  42. #include "llvm/Support/TargetSelect.h"
  43. #include "llvm/Support/Timer.h"
  44. #include "llvm/Support/raw_ostream.h"
  45. #include <memory>
  46. #include <set>
  47. #include <system_error>
  48. using namespace clang;
  49. using namespace clang::driver;
  50. using namespace llvm::opt;
  51. std::string GetExecutablePath(const char *Argv0, bool CanonicalPrefixes) {
  52. if (!CanonicalPrefixes) {
  53. SmallString<128> ExecutablePath(Argv0);
  54. // Do a PATH lookup if Argv0 isn't a valid path.
  55. if (!llvm::sys::fs::exists(ExecutablePath))
  56. if (llvm::ErrorOr<std::string> P =
  57. llvm::sys::findProgramByName(ExecutablePath))
  58. ExecutablePath = *P;
  59. return ExecutablePath.str();
  60. }
  61. // This just needs to be some symbol in the binary; C++ doesn't
  62. // allow taking the address of ::main however.
  63. void *P = (void*) (intptr_t) GetExecutablePath;
  64. return llvm::sys::fs::getMainExecutable(Argv0, P);
  65. }
  66. static const char *GetStableCStr(std::set<std::string> &SavedStrings,
  67. StringRef S) {
  68. return SavedStrings.insert(S).first->c_str();
  69. }
  70. /// ApplyQAOverride - Apply a list of edits to the input argument lists.
  71. ///
  72. /// The input string is a space separate list of edits to perform,
  73. /// they are applied in order to the input argument lists. Edits
  74. /// should be one of the following forms:
  75. ///
  76. /// '#': Silence information about the changes to the command line arguments.
  77. ///
  78. /// '^': Add FOO as a new argument at the beginning of the command line.
  79. ///
  80. /// '+': Add FOO as a new argument at the end of the command line.
  81. ///
  82. /// 's/XXX/YYY/': Substitute the regular expression XXX with YYY in the command
  83. /// line.
  84. ///
  85. /// 'xOPTION': Removes all instances of the literal argument OPTION.
  86. ///
  87. /// 'XOPTION': Removes all instances of the literal argument OPTION,
  88. /// and the following argument.
  89. ///
  90. /// 'Ox': Removes all flags matching 'O' or 'O[sz0-9]' and adds 'Ox'
  91. /// at the end of the command line.
  92. ///
  93. /// \param OS - The stream to write edit information to.
  94. /// \param Args - The vector of command line arguments.
  95. /// \param Edit - The override command to perform.
  96. /// \param SavedStrings - Set to use for storing string representations.
  97. static void ApplyOneQAOverride(raw_ostream &OS,
  98. SmallVectorImpl<const char*> &Args,
  99. StringRef Edit,
  100. std::set<std::string> &SavedStrings) {
  101. // This does not need to be efficient.
  102. if (Edit[0] == '^') {
  103. const char *Str =
  104. GetStableCStr(SavedStrings, Edit.substr(1));
  105. OS << "### Adding argument " << Str << " at beginning\n";
  106. Args.insert(Args.begin() + 1, Str);
  107. } else if (Edit[0] == '+') {
  108. const char *Str =
  109. GetStableCStr(SavedStrings, Edit.substr(1));
  110. OS << "### Adding argument " << Str << " at end\n";
  111. Args.push_back(Str);
  112. } else if (Edit[0] == 's' && Edit[1] == '/' && Edit.endswith("/") &&
  113. Edit.slice(2, Edit.size()-1).find('/') != StringRef::npos) {
  114. StringRef MatchPattern = Edit.substr(2).split('/').first;
  115. StringRef ReplPattern = Edit.substr(2).split('/').second;
  116. ReplPattern = ReplPattern.slice(0, ReplPattern.size()-1);
  117. for (unsigned i = 1, e = Args.size(); i != e; ++i) {
  118. // Ignore end-of-line response file markers
  119. if (Args[i] == nullptr)
  120. continue;
  121. std::string Repl = llvm::Regex(MatchPattern).sub(ReplPattern, Args[i]);
  122. if (Repl != Args[i]) {
  123. OS << "### Replacing '" << Args[i] << "' with '" << Repl << "'\n";
  124. Args[i] = GetStableCStr(SavedStrings, Repl);
  125. }
  126. }
  127. } else if (Edit[0] == 'x' || Edit[0] == 'X') {
  128. auto Option = Edit.substr(1);
  129. for (unsigned i = 1; i < Args.size();) {
  130. if (Option == Args[i]) {
  131. OS << "### Deleting argument " << Args[i] << '\n';
  132. Args.erase(Args.begin() + i);
  133. if (Edit[0] == 'X') {
  134. if (i < Args.size()) {
  135. OS << "### Deleting argument " << Args[i] << '\n';
  136. Args.erase(Args.begin() + i);
  137. } else
  138. OS << "### Invalid X edit, end of command line!\n";
  139. }
  140. } else
  141. ++i;
  142. }
  143. } else if (Edit[0] == 'O') {
  144. for (unsigned i = 1; i < Args.size();) {
  145. const char *A = Args[i];
  146. // Ignore end-of-line response file markers
  147. if (A == nullptr)
  148. continue;
  149. if (A[0] == '-' && A[1] == 'O' &&
  150. (A[2] == '\0' ||
  151. (A[3] == '\0' && (A[2] == 's' || A[2] == 'z' ||
  152. ('0' <= A[2] && A[2] <= '9'))))) {
  153. OS << "### Deleting argument " << Args[i] << '\n';
  154. Args.erase(Args.begin() + i);
  155. } else
  156. ++i;
  157. }
  158. OS << "### Adding argument " << Edit << " at end\n";
  159. Args.push_back(GetStableCStr(SavedStrings, '-' + Edit.str()));
  160. } else {
  161. OS << "### Unrecognized edit: " << Edit << "\n";
  162. }
  163. }
  164. /// ApplyQAOverride - Apply a comma separate list of edits to the
  165. /// input argument lists. See ApplyOneQAOverride.
  166. static void ApplyQAOverride(SmallVectorImpl<const char*> &Args,
  167. const char *OverrideStr,
  168. std::set<std::string> &SavedStrings) {
  169. raw_ostream *OS = &llvm::errs();
  170. if (OverrideStr[0] == '#') {
  171. ++OverrideStr;
  172. OS = &llvm::nulls();
  173. }
  174. *OS << "### CCC_OVERRIDE_OPTIONS: " << OverrideStr << "\n";
  175. // This does not need to be efficient.
  176. const char *S = OverrideStr;
  177. while (*S) {
  178. const char *End = ::strchr(S, ' ');
  179. if (!End)
  180. End = S + strlen(S);
  181. if (End != S)
  182. ApplyOneQAOverride(*OS, Args, std::string(S, End), SavedStrings);
  183. S = End;
  184. if (*S != '\0')
  185. ++S;
  186. }
  187. }
  188. extern int cc1_main(ArrayRef<const char *> Argv, const char *Argv0,
  189. void *MainAddr);
  190. extern int cc1as_main(ArrayRef<const char *> Argv, const char *Argv0,
  191. void *MainAddr);
  192. extern int cc1gen_reproducer_main(ArrayRef<const char *> Argv,
  193. const char *Argv0, void *MainAddr);
  194. static void insertTargetAndModeArgs(const ParsedClangName &NameParts,
  195. SmallVectorImpl<const char *> &ArgVector,
  196. std::set<std::string> &SavedStrings) {
  197. // Put target and mode arguments at the start of argument list so that
  198. // arguments specified in command line could override them. Avoid putting
  199. // them at index 0, as an option like '-cc1' must remain the first.
  200. int InsertionPoint = 0;
  201. if (ArgVector.size() > 0)
  202. ++InsertionPoint;
  203. if (NameParts.DriverMode) {
  204. // Add the mode flag to the arguments.
  205. ArgVector.insert(ArgVector.begin() + InsertionPoint,
  206. GetStableCStr(SavedStrings, NameParts.DriverMode));
  207. }
  208. if (NameParts.TargetIsValid) {
  209. const char *arr[] = {"-target", GetStableCStr(SavedStrings,
  210. NameParts.TargetPrefix)};
  211. ArgVector.insert(ArgVector.begin() + InsertionPoint,
  212. std::begin(arr), std::end(arr));
  213. }
  214. }
  215. static void getCLEnvVarOptions(std::string &EnvValue, llvm::StringSaver &Saver,
  216. SmallVectorImpl<const char *> &Opts) {
  217. llvm::cl::TokenizeWindowsCommandLine(EnvValue, Saver, Opts);
  218. // The first instance of '#' should be replaced with '=' in each option.
  219. for (const char *Opt : Opts)
  220. if (char *NumberSignPtr = const_cast<char *>(::strchr(Opt, '#')))
  221. *NumberSignPtr = '=';
  222. }
  223. static void SetBackdoorDriverOutputsFromEnvVars(Driver &TheDriver) {
  224. // Handle CC_PRINT_OPTIONS and CC_PRINT_OPTIONS_FILE.
  225. TheDriver.CCPrintOptions = !!::getenv("CC_PRINT_OPTIONS");
  226. if (TheDriver.CCPrintOptions)
  227. TheDriver.CCPrintOptionsFilename = ::getenv("CC_PRINT_OPTIONS_FILE");
  228. // Handle CC_PRINT_HEADERS and CC_PRINT_HEADERS_FILE.
  229. TheDriver.CCPrintHeaders = !!::getenv("CC_PRINT_HEADERS");
  230. if (TheDriver.CCPrintHeaders)
  231. TheDriver.CCPrintHeadersFilename = ::getenv("CC_PRINT_HEADERS_FILE");
  232. // Handle CC_LOG_DIAGNOSTICS and CC_LOG_DIAGNOSTICS_FILE.
  233. TheDriver.CCLogDiagnostics = !!::getenv("CC_LOG_DIAGNOSTICS");
  234. if (TheDriver.CCLogDiagnostics)
  235. TheDriver.CCLogDiagnosticsFilename = ::getenv("CC_LOG_DIAGNOSTICS_FILE");
  236. }
  237. static void FixupDiagPrefixExeName(TextDiagnosticPrinter *DiagClient,
  238. const std::string &Path) {
  239. // If the clang binary happens to be named cl.exe for compatibility reasons,
  240. // use clang-cl.exe as the prefix to avoid confusion between clang and MSVC.
  241. StringRef ExeBasename(llvm::sys::path::stem(Path));
  242. if (ExeBasename.equals_lower("cl"))
  243. ExeBasename = "clang-cl";
  244. DiagClient->setPrefix(ExeBasename);
  245. }
  246. // This lets us create the DiagnosticsEngine with a properly-filled-out
  247. // DiagnosticOptions instance.
  248. static DiagnosticOptions *
  249. CreateAndPopulateDiagOpts(ArrayRef<const char *> argv) {
  250. auto *DiagOpts = new DiagnosticOptions;
  251. std::unique_ptr<OptTable> Opts(createDriverOptTable());
  252. unsigned MissingArgIndex, MissingArgCount;
  253. InputArgList Args =
  254. Opts->ParseArgs(argv.slice(1), MissingArgIndex, MissingArgCount);
  255. // We ignore MissingArgCount and the return value of ParseDiagnosticArgs.
  256. // Any errors that would be diagnosed here will also be diagnosed later,
  257. // when the DiagnosticsEngine actually exists.
  258. (void)ParseDiagnosticArgs(*DiagOpts, Args);
  259. return DiagOpts;
  260. }
  261. static void SetInstallDir(SmallVectorImpl<const char *> &argv,
  262. Driver &TheDriver, bool CanonicalPrefixes) {
  263. // Attempt to find the original path used to invoke the driver, to determine
  264. // the installed path. We do this manually, because we want to support that
  265. // path being a symlink.
  266. SmallString<128> InstalledPath(argv[0]);
  267. // Do a PATH lookup, if there are no directory components.
  268. if (llvm::sys::path::filename(InstalledPath) == InstalledPath)
  269. if (llvm::ErrorOr<std::string> Tmp = llvm::sys::findProgramByName(
  270. llvm::sys::path::filename(InstalledPath.str())))
  271. InstalledPath = *Tmp;
  272. // FIXME: We don't actually canonicalize this, we just make it absolute.
  273. if (CanonicalPrefixes)
  274. llvm::sys::fs::make_absolute(InstalledPath);
  275. StringRef InstalledPathParent(llvm::sys::path::parent_path(InstalledPath));
  276. if (llvm::sys::fs::exists(InstalledPathParent))
  277. TheDriver.setInstalledDir(InstalledPathParent);
  278. }
  279. static int ExecuteCC1Tool(ArrayRef<const char *> argv, StringRef Tool) {
  280. void *GetExecutablePathVP = (void *)(intptr_t) GetExecutablePath;
  281. if (Tool == "")
  282. return cc1_main(argv.slice(2), argv[0], GetExecutablePathVP);
  283. if (Tool == "as")
  284. return cc1as_main(argv.slice(2), argv[0], GetExecutablePathVP);
  285. if (Tool == "gen-reproducer")
  286. return cc1gen_reproducer_main(argv.slice(2), argv[0], GetExecutablePathVP);
  287. // Reject unknown tools.
  288. llvm::errs() << "error: unknown integrated tool '" << Tool << "'. "
  289. << "Valid tools include '-cc1' and '-cc1as'.\n";
  290. return 1;
  291. }
  292. int main(int argc_, const char **argv_) {
  293. noteBottomOfStack();
  294. llvm::InitLLVM X(argc_, argv_);
  295. SmallVector<const char *, 256> argv(argv_, argv_ + argc_);
  296. if (llvm::sys::Process::FixupStandardFileDescriptors())
  297. return 1;
  298. llvm::InitializeAllTargets();
  299. auto TargetAndMode = ToolChain::getTargetAndModeFromProgramName(argv[0]);
  300. llvm::BumpPtrAllocator A;
  301. llvm::StringSaver Saver(A);
  302. // Parse response files using the GNU syntax, unless we're in CL mode. There
  303. // are two ways to put clang in CL compatibility mode: argv[0] is either
  304. // clang-cl or cl, or --driver-mode=cl is on the command line. The normal
  305. // command line parsing can't happen until after response file parsing, so we
  306. // have to manually search for a --driver-mode=cl argument the hard way.
  307. // Finally, our -cc1 tools don't care which tokenization mode we use because
  308. // response files written by clang will tokenize the same way in either mode.
  309. bool ClangCLMode = false;
  310. if (StringRef(TargetAndMode.DriverMode).equals("--driver-mode=cl") ||
  311. llvm::find_if(argv, [](const char *F) {
  312. return F && strcmp(F, "--driver-mode=cl") == 0;
  313. }) != argv.end()) {
  314. ClangCLMode = true;
  315. }
  316. enum { Default, POSIX, Windows } RSPQuoting = Default;
  317. for (const char *F : argv) {
  318. if (strcmp(F, "--rsp-quoting=posix") == 0)
  319. RSPQuoting = POSIX;
  320. else if (strcmp(F, "--rsp-quoting=windows") == 0)
  321. RSPQuoting = Windows;
  322. }
  323. // Determines whether we want nullptr markers in argv to indicate response
  324. // files end-of-lines. We only use this for the /LINK driver argument with
  325. // clang-cl.exe on Windows.
  326. bool MarkEOLs = ClangCLMode;
  327. llvm::cl::TokenizerCallback Tokenizer;
  328. if (RSPQuoting == Windows || (RSPQuoting == Default && ClangCLMode))
  329. Tokenizer = &llvm::cl::TokenizeWindowsCommandLine;
  330. else
  331. Tokenizer = &llvm::cl::TokenizeGNUCommandLine;
  332. if (MarkEOLs && argv.size() > 1 && StringRef(argv[1]).startswith("-cc1"))
  333. MarkEOLs = false;
  334. llvm::cl::ExpandResponseFiles(Saver, Tokenizer, argv, MarkEOLs);
  335. // Handle -cc1 integrated tools, even if -cc1 was expanded from a response
  336. // file.
  337. auto FirstArg = std::find_if(argv.begin() + 1, argv.end(),
  338. [](const char *A) { return A != nullptr; });
  339. if (FirstArg != argv.end() && StringRef(*FirstArg).startswith("-cc1")) {
  340. // If -cc1 came from a response file, remove the EOL sentinels.
  341. if (MarkEOLs) {
  342. auto newEnd = std::remove(argv.begin(), argv.end(), nullptr);
  343. argv.resize(newEnd - argv.begin());
  344. }
  345. return ExecuteCC1Tool(argv, argv[1] + 4);
  346. }
  347. bool CanonicalPrefixes = true;
  348. for (int i = 1, size = argv.size(); i < size; ++i) {
  349. // Skip end-of-line response file markers
  350. if (argv[i] == nullptr)
  351. continue;
  352. if (StringRef(argv[i]) == "-no-canonical-prefixes") {
  353. CanonicalPrefixes = false;
  354. break;
  355. }
  356. }
  357. // Handle CL and _CL_ which permits additional command line options to be
  358. // prepended or appended.
  359. if (ClangCLMode) {
  360. // Arguments in "CL" are prepended.
  361. llvm::Optional<std::string> OptCL = llvm::sys::Process::GetEnv("CL");
  362. if (OptCL.hasValue()) {
  363. SmallVector<const char *, 8> PrependedOpts;
  364. getCLEnvVarOptions(OptCL.getValue(), Saver, PrependedOpts);
  365. // Insert right after the program name to prepend to the argument list.
  366. argv.insert(argv.begin() + 1, PrependedOpts.begin(), PrependedOpts.end());
  367. }
  368. // Arguments in "_CL_" are appended.
  369. llvm::Optional<std::string> Opt_CL_ = llvm::sys::Process::GetEnv("_CL_");
  370. if (Opt_CL_.hasValue()) {
  371. SmallVector<const char *, 8> AppendedOpts;
  372. getCLEnvVarOptions(Opt_CL_.getValue(), Saver, AppendedOpts);
  373. // Insert at the end of the argument list to append.
  374. argv.append(AppendedOpts.begin(), AppendedOpts.end());
  375. }
  376. }
  377. std::set<std::string> SavedStrings;
  378. // Handle CCC_OVERRIDE_OPTIONS, used for editing a command line behind the
  379. // scenes.
  380. if (const char *OverrideStr = ::getenv("CCC_OVERRIDE_OPTIONS")) {
  381. // FIXME: Driver shouldn't take extra initial argument.
  382. ApplyQAOverride(argv, OverrideStr, SavedStrings);
  383. }
  384. std::string Path = GetExecutablePath(argv[0], CanonicalPrefixes);
  385. IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts =
  386. CreateAndPopulateDiagOpts(argv);
  387. TextDiagnosticPrinter *DiagClient
  388. = new TextDiagnosticPrinter(llvm::errs(), &*DiagOpts);
  389. FixupDiagPrefixExeName(DiagClient, Path);
  390. IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs());
  391. DiagnosticsEngine Diags(DiagID, &*DiagOpts, DiagClient);
  392. if (!DiagOpts->DiagnosticSerializationFile.empty()) {
  393. auto SerializedConsumer =
  394. clang::serialized_diags::create(DiagOpts->DiagnosticSerializationFile,
  395. &*DiagOpts, /*MergeChildRecords=*/true);
  396. Diags.setClient(new ChainedDiagnosticConsumer(
  397. Diags.takeClient(), std::move(SerializedConsumer)));
  398. }
  399. ProcessWarningOptions(Diags, *DiagOpts, /*ReportDiags=*/false);
  400. Driver TheDriver(Path, llvm::sys::getDefaultTargetTriple(), Diags);
  401. SetInstallDir(argv, TheDriver, CanonicalPrefixes);
  402. TheDriver.setTargetAndMode(TargetAndMode);
  403. insertTargetAndModeArgs(TargetAndMode, argv, SavedStrings);
  404. SetBackdoorDriverOutputsFromEnvVars(TheDriver);
  405. std::unique_ptr<Compilation> C(TheDriver.BuildCompilation(argv));
  406. int Res = 1;
  407. if (C && !C->containsError()) {
  408. SmallVector<std::pair<int, const Command *>, 4> FailingCommands;
  409. Res = TheDriver.ExecuteCompilation(*C, FailingCommands);
  410. // Force a crash to test the diagnostics.
  411. if (TheDriver.GenReproducer) {
  412. Diags.Report(diag::err_drv_force_crash)
  413. << !::getenv("FORCE_CLANG_DIAGNOSTICS_CRASH");
  414. // Pretend that every command failed.
  415. FailingCommands.clear();
  416. for (const auto &J : C->getJobs())
  417. if (const Command *C = dyn_cast<Command>(&J))
  418. FailingCommands.push_back(std::make_pair(-1, C));
  419. }
  420. for (const auto &P : FailingCommands) {
  421. int CommandRes = P.first;
  422. const Command *FailingCommand = P.second;
  423. if (!Res)
  424. Res = CommandRes;
  425. // If result status is < 0, then the driver command signalled an error.
  426. // If result status is 70, then the driver command reported a fatal error.
  427. // On Windows, abort will return an exit code of 3. In these cases,
  428. // generate additional diagnostic information if possible.
  429. bool DiagnoseCrash = CommandRes < 0 || CommandRes == 70;
  430. #ifdef _WIN32
  431. DiagnoseCrash |= CommandRes == 3;
  432. #endif
  433. if (DiagnoseCrash) {
  434. TheDriver.generateCompilationDiagnostics(*C, *FailingCommand);
  435. break;
  436. }
  437. }
  438. }
  439. Diags.getClient()->finish();
  440. // If any timers were active but haven't been destroyed yet, print their
  441. // results now. This happens in -disable-free mode.
  442. llvm::TimerGroup::printAll(llvm::errs());
  443. #ifdef _WIN32
  444. // Exit status should not be negative on Win32, unless abnormal termination.
  445. // Once abnormal termiation was caught, negative status should not be
  446. // propagated.
  447. if (Res < 0)
  448. Res = 1;
  449. #endif
  450. // If we have multiple failing commands, we return the result of the first
  451. // failing command.
  452. return Res;
  453. }