Daniel Dunbar | 2fcaa54 | 2010-05-20 17:49:16 +0000 | [diff] [blame] | 1 | //===-- cc1_main.cpp - Clang CC1 Compiler Frontend ------------------------===// |
Daniel Dunbar | 51cd8f0 | 2009-11-19 07:37:51 +0000 | [diff] [blame] | 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 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 |
Daniel Dunbar | 51cd8f0 | 2009-11-19 07:37:51 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | // |
Daniel Dunbar | f72bdf7 | 2009-12-11 22:20:12 +0000 | [diff] [blame] | 9 | // This is the entry point to the clang -cc1 functionality, which implements the |
| 10 | // core compiler functionality along with a number of additional tools for |
| 11 | // demonstration and testing purposes. |
Daniel Dunbar | 51cd8f0 | 2009-11-19 07:37:51 +0000 | [diff] [blame] | 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
David Blaikie | 9941da4 | 2018-11-17 18:04:13 +0000 | [diff] [blame] | 15 | #include "clang/Basic/Stack.h" |
Adrian Prantl | bc06858 | 2015-07-08 01:00:30 +0000 | [diff] [blame] | 16 | #include "clang/CodeGen/ObjectFilePCHContainerOperations.h" |
Chris Bieneman | a6b39ab | 2016-08-23 20:07:07 +0000 | [diff] [blame] | 17 | #include "clang/Config/config.h" |
Daniel Dunbar | f72bdf7 | 2009-12-11 22:20:12 +0000 | [diff] [blame] | 18 | #include "clang/Driver/DriverDiagnostic.h" |
Chandler Carruth | cc0694c | 2012-12-04 09:25:21 +0000 | [diff] [blame] | 19 | #include "clang/Driver/Options.h" |
Daniel Dunbar | f72bdf7 | 2009-12-11 22:20:12 +0000 | [diff] [blame] | 20 | #include "clang/Frontend/CompilerInstance.h" |
| 21 | #include "clang/Frontend/CompilerInvocation.h" |
Daniel Dunbar | f72bdf7 | 2009-12-11 22:20:12 +0000 | [diff] [blame] | 22 | #include "clang/Frontend/FrontendDiagnostic.h" |
Daniel Dunbar | f72bdf7 | 2009-12-11 22:20:12 +0000 | [diff] [blame] | 23 | #include "clang/Frontend/TextDiagnosticBuffer.h" |
| 24 | #include "clang/Frontend/TextDiagnosticPrinter.h" |
Kostya Serebryany | ce2c726 | 2013-12-27 08:11:08 +0000 | [diff] [blame] | 25 | #include "clang/Frontend/Utils.h" |
Peter Collingbourne | 85dd0bd | 2010-08-24 00:31:22 +0000 | [diff] [blame] | 26 | #include "clang/FrontendTool/Utils.h" |
Douglas Gregor | 171b780 | 2010-03-30 17:33:59 +0000 | [diff] [blame] | 27 | #include "llvm/ADT/Statistic.h" |
Nico Weber | d637c05 | 2018-04-30 13:52:15 +0000 | [diff] [blame] | 28 | #include "llvm/Config/llvm-config.h" |
Chandler Carruth | cc0694c | 2012-12-04 09:25:21 +0000 | [diff] [blame] | 29 | #include "llvm/LinkAllPasses.h" |
David Blaikie | 9941da4 | 2018-11-17 18:04:13 +0000 | [diff] [blame] | 30 | #include "llvm/Option/Arg.h" |
Reid Kleckner | 898229a | 2013-06-14 17:17:23 +0000 | [diff] [blame] | 31 | #include "llvm/Option/ArgList.h" |
| 32 | #include "llvm/Option/OptTable.h" |
David Blaikie | 9941da4 | 2018-11-17 18:04:13 +0000 | [diff] [blame] | 33 | #include "llvm/Support/BuryPointer.h" |
Richard Smith | 194b6a3 | 2016-08-17 01:05:07 +0000 | [diff] [blame] | 34 | #include "llvm/Support/Compiler.h" |
Daniel Dunbar | f72bdf7 | 2009-12-11 22:20:12 +0000 | [diff] [blame] | 35 | #include "llvm/Support/ErrorHandling.h" |
| 36 | #include "llvm/Support/ManagedStatic.h" |
Anton Afanasyev | d880de2 | 2019-03-30 08:42:48 +0000 | [diff] [blame] | 37 | #include "llvm/Support/Path.h" |
Chad Rosier | 7ea7397 | 2012-11-12 19:39:37 +0000 | [diff] [blame] | 38 | #include "llvm/Support/Signals.h" |
Evan Cheng | 494eb06 | 2011-08-24 18:09:14 +0000 | [diff] [blame] | 39 | #include "llvm/Support/TargetSelect.h" |
Anton Afanasyev | d880de2 | 2019-03-30 08:42:48 +0000 | [diff] [blame] | 40 | #include "llvm/Support/TimeProfiler.h" |
Chris Lattner | 09f8cc8 | 2010-03-30 05:39:52 +0000 | [diff] [blame] | 41 | #include "llvm/Support/Timer.h" |
Daniel Dunbar | 51cd8f0 | 2009-11-19 07:37:51 +0000 | [diff] [blame] | 42 | #include "llvm/Support/raw_ostream.h" |
Daniel Dunbar | f72bdf7 | 2009-12-11 22:20:12 +0000 | [diff] [blame] | 43 | #include <cstdio> |
Richard Smith | c33b837 | 2016-08-18 18:22:22 +0000 | [diff] [blame] | 44 | |
Chris Bieneman | a6b39ab | 2016-08-23 20:07:07 +0000 | [diff] [blame] | 45 | #ifdef CLANG_HAVE_RLIMITS |
Richard Smith | 194b6a3 | 2016-08-17 01:05:07 +0000 | [diff] [blame] | 46 | #include <sys/resource.h> |
| 47 | #endif |
Richard Smith | c33b837 | 2016-08-18 18:22:22 +0000 | [diff] [blame] | 48 | |
Daniel Dunbar | f72bdf7 | 2009-12-11 22:20:12 +0000 | [diff] [blame] | 49 | using namespace clang; |
Reid Kleckner | 898229a | 2013-06-14 17:17:23 +0000 | [diff] [blame] | 50 | using namespace llvm::opt; |
Daniel Dunbar | 51cd8f0 | 2009-11-19 07:37:51 +0000 | [diff] [blame] | 51 | |
Daniel Dunbar | f72bdf7 | 2009-12-11 22:20:12 +0000 | [diff] [blame] | 52 | //===----------------------------------------------------------------------===// |
| 53 | // Main driver |
| 54 | //===----------------------------------------------------------------------===// |
| 55 | |
Chad Rosier | 05c71aa | 2013-03-27 18:28:23 +0000 | [diff] [blame] | 56 | static void LLVMErrorHandler(void *UserData, const std::string &Message, |
| 57 | bool GenCrashDiag) { |
David Blaikie | 9c902b5 | 2011-09-25 23:23:43 +0000 | [diff] [blame] | 58 | DiagnosticsEngine &Diags = *static_cast<DiagnosticsEngine*>(UserData); |
Daniel Dunbar | f72bdf7 | 2009-12-11 22:20:12 +0000 | [diff] [blame] | 59 | |
| 60 | Diags.Report(diag::err_fe_error_backend) << Message; |
| 61 | |
Chad Rosier | 7ea7397 | 2012-11-12 19:39:37 +0000 | [diff] [blame] | 62 | // Run the interrupt handlers to make sure any special cleanups get done, in |
| 63 | // particular that we remove files registered with RemoveFileOnSignal. |
| 64 | llvm::sys::RunInterruptHandlers(); |
| 65 | |
Chad Rosier | ad6e96d | 2012-11-12 21:32:24 +0000 | [diff] [blame] | 66 | // We cannot recover from llvm errors. When reporting a fatal error, exit |
Chad Rosier | 05c71aa | 2013-03-27 18:28:23 +0000 | [diff] [blame] | 67 | // with status 70 to generate crash diagnostics. For BSD systems this is |
| 68 | // defined as an internal software error. Otherwise, exit with status 1. |
| 69 | exit(GenCrashDiag ? 70 : 1); |
Daniel Dunbar | f72bdf7 | 2009-12-11 22:20:12 +0000 | [diff] [blame] | 70 | } |
| 71 | |
Sebastian Pop | 17fac04 | 2014-03-14 04:04:27 +0000 | [diff] [blame] | 72 | #ifdef LINK_POLLY_INTO_TOOLS |
| 73 | namespace polly { |
| 74 | void initializePollyPasses(llvm::PassRegistry &Registry); |
| 75 | } |
| 76 | #endif |
| 77 | |
Chris Bieneman | a6b39ab | 2016-08-23 20:07:07 +0000 | [diff] [blame] | 78 | #ifdef CLANG_HAVE_RLIMITS |
Richard Smith | 194b6a3 | 2016-08-17 01:05:07 +0000 | [diff] [blame] | 79 | #if defined(__linux__) && defined(__PIE__) |
Richard Smith | f80a27e | 2016-10-14 19:51:36 +0000 | [diff] [blame] | 80 | static size_t getCurrentStackAllocation() { |
| 81 | // If we can't compute the current stack usage, allow for 512K of command |
| 82 | // line arguments and environment. |
| 83 | size_t Usage = 512 * 1024; |
| 84 | if (FILE *StatFile = fopen("/proc/self/stat", "r")) { |
| 85 | // We assume that the stack extends from its current address to the end of |
| 86 | // the environment space. In reality, there is another string literal (the |
| 87 | // program name) after the environment, but this is close enough (we only |
| 88 | // need to be within 100K or so). |
| 89 | unsigned long StackPtr, EnvEnd; |
Richard Smith | 49db68d | 2016-10-15 01:59:52 +0000 | [diff] [blame] | 90 | // Disable silly GCC -Wformat warning that complains about length |
| 91 | // modifiers on ignored format specifiers. We want to retain these |
| 92 | // for documentation purposes even though they have no effect. |
| 93 | #if defined(__GNUC__) && !defined(__clang__) |
| 94 | #pragma GCC diagnostic push |
| 95 | #pragma GCC diagnostic ignored "-Wformat" |
| 96 | #endif |
Richard Smith | f80a27e | 2016-10-14 19:51:36 +0000 | [diff] [blame] | 97 | if (fscanf(StatFile, |
| 98 | "%*d %*s %*c %*d %*d %*d %*d %*d %*u %*lu %*lu %*lu %*lu %*lu " |
| 99 | "%*lu %*ld %*ld %*ld %*ld %*ld %*ld %*llu %*lu %*ld %*lu %*lu " |
| 100 | "%*lu %*lu %lu %*lu %*lu %*lu %*lu %*lu %*llu %*lu %*lu %*d %*d " |
| 101 | "%*u %*u %*llu %*lu %*ld %*lu %*lu %*lu %*lu %*lu %*lu %lu %*d", |
| 102 | &StackPtr, &EnvEnd) == 2) { |
Richard Smith | 49db68d | 2016-10-15 01:59:52 +0000 | [diff] [blame] | 103 | #if defined(__GNUC__) && !defined(__clang__) |
| 104 | #pragma GCC diagnostic pop |
| 105 | #endif |
Richard Smith | f80a27e | 2016-10-14 19:51:36 +0000 | [diff] [blame] | 106 | Usage = StackPtr < EnvEnd ? EnvEnd - StackPtr : StackPtr - EnvEnd; |
| 107 | } |
| 108 | fclose(StatFile); |
| 109 | } |
| 110 | return Usage; |
| 111 | } |
| 112 | |
| 113 | #include <alloca.h> |
| 114 | |
Richard Smith | 194b6a3 | 2016-08-17 01:05:07 +0000 | [diff] [blame] | 115 | LLVM_ATTRIBUTE_NOINLINE |
Richard Smith | 0a7b297 | 2018-07-03 21:34:13 +0000 | [diff] [blame] | 116 | static void ensureStackAddressSpace() { |
Richard Smith | 194b6a3 | 2016-08-17 01:05:07 +0000 | [diff] [blame] | 117 | // Linux kernels prior to 4.1 will sometimes locate the heap of a PIE binary |
| 118 | // relatively close to the stack (they are only guaranteed to be 128MiB |
| 119 | // apart). This results in crashes if we happen to heap-allocate more than |
| 120 | // 128MiB before we reach our stack high-water mark. |
| 121 | // |
| 122 | // To avoid these crashes, ensure that we have sufficient virtual memory |
Richard Smith | f80a27e | 2016-10-14 19:51:36 +0000 | [diff] [blame] | 123 | // pages allocated before we start running. |
| 124 | size_t Curr = getCurrentStackAllocation(); |
Richard Smith | 0a7b297 | 2018-07-03 21:34:13 +0000 | [diff] [blame] | 125 | const int kTargetStack = DesiredStackSize - 256 * 1024; |
Richard Smith | f80a27e | 2016-10-14 19:51:36 +0000 | [diff] [blame] | 126 | if (Curr < kTargetStack) { |
| 127 | volatile char *volatile Alloc = |
| 128 | static_cast<volatile char *>(alloca(kTargetStack - Curr)); |
| 129 | Alloc[0] = 0; |
| 130 | Alloc[kTargetStack - Curr - 1] = 0; |
| 131 | } |
Richard Smith | 194b6a3 | 2016-08-17 01:05:07 +0000 | [diff] [blame] | 132 | } |
| 133 | #else |
| 134 | static void ensureStackAddressSpace() {} |
| 135 | #endif |
| 136 | |
| 137 | /// Attempt to ensure that we have at least 8MiB of usable stack space. |
| 138 | static void ensureSufficientStack() { |
| 139 | struct rlimit rlim; |
| 140 | if (getrlimit(RLIMIT_STACK, &rlim) != 0) |
| 141 | return; |
| 142 | |
| 143 | // Increase the soft stack limit to our desired level, if necessary and |
| 144 | // possible. |
Fangrui Song | 4eab1ba | 2018-07-25 06:57:31 +0000 | [diff] [blame] | 145 | if (rlim.rlim_cur != RLIM_INFINITY && |
| 146 | rlim.rlim_cur < rlim_t(DesiredStackSize)) { |
Richard Smith | 194b6a3 | 2016-08-17 01:05:07 +0000 | [diff] [blame] | 147 | // Try to allocate sufficient stack. |
Fangrui Song | 4eab1ba | 2018-07-25 06:57:31 +0000 | [diff] [blame] | 148 | if (rlim.rlim_max == RLIM_INFINITY || |
| 149 | rlim.rlim_max >= rlim_t(DesiredStackSize)) |
Richard Smith | 0a7b297 | 2018-07-03 21:34:13 +0000 | [diff] [blame] | 150 | rlim.rlim_cur = DesiredStackSize; |
Richard Smith | 194b6a3 | 2016-08-17 01:05:07 +0000 | [diff] [blame] | 151 | else if (rlim.rlim_cur == rlim.rlim_max) |
| 152 | return; |
| 153 | else |
| 154 | rlim.rlim_cur = rlim.rlim_max; |
| 155 | |
| 156 | if (setrlimit(RLIMIT_STACK, &rlim) != 0 || |
Richard Smith | 0a7b297 | 2018-07-03 21:34:13 +0000 | [diff] [blame] | 157 | rlim.rlim_cur != DesiredStackSize) |
Richard Smith | 194b6a3 | 2016-08-17 01:05:07 +0000 | [diff] [blame] | 158 | return; |
| 159 | } |
| 160 | |
Richard Smith | 0a7b297 | 2018-07-03 21:34:13 +0000 | [diff] [blame] | 161 | // We should now have a stack of size at least DesiredStackSize. Ensure |
Richard Smith | 194b6a3 | 2016-08-17 01:05:07 +0000 | [diff] [blame] | 162 | // that we can actually use that much, if necessary. |
| 163 | ensureStackAddressSpace(); |
| 164 | } |
| 165 | #else |
Richard Smith | 525ce25 | 2016-08-17 02:22:39 +0000 | [diff] [blame] | 166 | static void ensureSufficientStack() {} |
Richard Smith | 194b6a3 | 2016-08-17 01:05:07 +0000 | [diff] [blame] | 167 | #endif |
| 168 | |
Sean Silva | 070cd2d | 2014-08-15 21:38:36 +0000 | [diff] [blame] | 169 | int cc1_main(ArrayRef<const char *> Argv, const char *Argv0, void *MainAddr) { |
Richard Smith | 194b6a3 | 2016-08-17 01:05:07 +0000 | [diff] [blame] | 170 | ensureSufficientStack(); |
| 171 | |
Adrian Prantl | fb2398d | 2015-07-17 01:19:54 +0000 | [diff] [blame] | 172 | std::unique_ptr<CompilerInstance> Clang(new CompilerInstance()); |
Dylan Noblesmith | c95d819 | 2012-02-20 14:00:23 +0000 | [diff] [blame] | 173 | IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs()); |
Daniel Dunbar | e922d9b | 2010-02-16 01:54:47 +0000 | [diff] [blame] | 174 | |
Adrian Prantl | fb2398d | 2015-07-17 01:19:54 +0000 | [diff] [blame] | 175 | // Register the support for object-file-wrapped Clang modules. |
| 176 | auto PCHOps = Clang->getPCHContainerOperations(); |
| 177 | PCHOps->registerWriter(llvm::make_unique<ObjectFilePCHContainerWriter>()); |
| 178 | PCHOps->registerReader(llvm::make_unique<ObjectFilePCHContainerReader>()); |
| 179 | |
Daniel Dunbar | f72bdf7 | 2009-12-11 22:20:12 +0000 | [diff] [blame] | 180 | // Initialize targets first, so that --version shows registered targets. |
| 181 | llvm::InitializeAllTargets(); |
Evan Cheng | c391a58 | 2011-07-22 21:59:11 +0000 | [diff] [blame] | 182 | llvm::InitializeAllTargetMCs(); |
Daniel Dunbar | f72bdf7 | 2009-12-11 22:20:12 +0000 | [diff] [blame] | 183 | llvm::InitializeAllAsmPrinters(); |
Chris Lattner | 61955ab | 2010-04-05 23:33:20 +0000 | [diff] [blame] | 184 | llvm::InitializeAllAsmParsers(); |
Daniel Dunbar | f72bdf7 | 2009-12-11 22:20:12 +0000 | [diff] [blame] | 185 | |
Sebastian Pop | 17fac04 | 2014-03-14 04:04:27 +0000 | [diff] [blame] | 186 | #ifdef LINK_POLLY_INTO_TOOLS |
| 187 | llvm::PassRegistry &Registry = *llvm::PassRegistry::getPassRegistry(); |
| 188 | polly::initializePollyPasses(Registry); |
| 189 | #endif |
| 190 | |
Daniel Dunbar | f72bdf7 | 2009-12-11 22:20:12 +0000 | [diff] [blame] | 191 | // Buffer diagnostics from argument parsing so that we can output them using a |
| 192 | // well formed diagnostic object. |
Douglas Gregor | 811db4e | 2012-10-23 22:26:28 +0000 | [diff] [blame] | 193 | IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts = new DiagnosticOptions(); |
Douglas Gregor | 2dd19f1 | 2010-08-18 22:29:43 +0000 | [diff] [blame] | 194 | TextDiagnosticBuffer *DiagsBuffer = new TextDiagnosticBuffer; |
Douglas Gregor | 811db4e | 2012-10-23 22:26:28 +0000 | [diff] [blame] | 195 | DiagnosticsEngine Diags(DiagID, &*DiagOpts, DiagsBuffer); |
Sean Silva | 070cd2d | 2014-08-15 21:38:36 +0000 | [diff] [blame] | 196 | bool Success = CompilerInvocation::CreateFromArgs( |
| 197 | Clang->getInvocation(), Argv.begin(), Argv.end(), Diags); |
Daniel Dunbar | d613677 | 2009-12-13 03:45:58 +0000 | [diff] [blame] | 198 | |
Anton Afanasyev | d880de2 | 2019-03-30 08:42:48 +0000 | [diff] [blame] | 199 | if (Clang->getFrontendOpts().TimeTrace) |
| 200 | llvm::timeTraceProfilerInitialize(); |
| 201 | |
Daniel Dunbar | d613677 | 2009-12-13 03:45:58 +0000 | [diff] [blame] | 202 | // Infer the builtin include path if unspecified. |
Daniel Dunbar | 30b24e9 | 2010-03-23 05:09:16 +0000 | [diff] [blame] | 203 | if (Clang->getHeaderSearchOpts().UseBuiltinIncludes && |
| 204 | Clang->getHeaderSearchOpts().ResourceDir.empty()) |
| 205 | Clang->getHeaderSearchOpts().ResourceDir = |
Daniel Dunbar | a5a166d | 2009-12-15 00:06:45 +0000 | [diff] [blame] | 206 | CompilerInvocation::GetResourcesPath(Argv0, MainAddr); |
Daniel Dunbar | f72bdf7 | 2009-12-11 22:20:12 +0000 | [diff] [blame] | 207 | |
Daniel Dunbar | 1cdf04c | 2010-08-12 02:53:07 +0000 | [diff] [blame] | 208 | // Create the actual diagnostics engine. |
Sean Silva | f1b49e2 | 2013-01-20 01:58:28 +0000 | [diff] [blame] | 209 | Clang->createDiagnostics(); |
Daniel Dunbar | 1cdf04c | 2010-08-12 02:53:07 +0000 | [diff] [blame] | 210 | if (!Clang->hasDiagnostics()) |
| 211 | return 1; |
| 212 | |
| 213 | // Set an error handler, so that any LLVM backend diagnostics go through our |
| 214 | // error handler. |
| 215 | llvm::install_fatal_error_handler(LLVMErrorHandler, |
| 216 | static_cast<void*>(&Clang->getDiagnostics())); |
| 217 | |
Douglas Gregor | 2dd19f1 | 2010-08-18 22:29:43 +0000 | [diff] [blame] | 218 | DiagsBuffer->FlushDiagnostics(Clang->getDiagnostics()); |
Argyrios Kyrtzidis | be6d89d | 2012-01-25 20:00:43 +0000 | [diff] [blame] | 219 | if (!Success) |
| 220 | return 1; |
Daniel Dunbar | 1cdf04c | 2010-08-12 02:53:07 +0000 | [diff] [blame] | 221 | |
Daniel Dunbar | e9e91b0 | 2010-08-12 02:53:12 +0000 | [diff] [blame] | 222 | // Execute the frontend actions. |
Anton Afanasyev | d880de2 | 2019-03-30 08:42:48 +0000 | [diff] [blame] | 223 | { |
| 224 | llvm::TimeTraceScope TimeScope("ExecuteCompiler", StringRef("")); |
| 225 | Success = ExecuteCompilerInvocation(Clang.get()); |
| 226 | } |
Daniel Dunbar | 30b24e9 | 2010-03-23 05:09:16 +0000 | [diff] [blame] | 227 | |
Chris Lattner | 09f8cc8 | 2010-03-30 05:39:52 +0000 | [diff] [blame] | 228 | // If any timers were active but haven't been destroyed yet, print their |
| 229 | // results now. This happens in -disable-free mode. |
| 230 | llvm::TimerGroup::printAll(llvm::errs()); |
Daniel Dunbar | 2be9674 | 2010-08-02 15:31:28 +0000 | [diff] [blame] | 231 | |
Anton Afanasyev | d880de2 | 2019-03-30 08:42:48 +0000 | [diff] [blame] | 232 | if (llvm::timeTraceProfilerEnabled()) { |
| 233 | SmallString<128> Path(Clang->getFrontendOpts().OutputFile); |
| 234 | llvm::sys::path::replace_extension(Path, "json"); |
| 235 | auto profilerOutput = |
| 236 | Clang->createOutputFile(Path.str(), |
| 237 | /*Binary=*/false, |
| 238 | /*RemoveFileOnSignal=*/false, "", |
| 239 | /*Extension=*/"json", |
| 240 | /*useTemporary=*/false); |
| 241 | |
Anton Afanasyev | 2653672 | 2019-04-15 21:02:47 +0000 | [diff] [blame] | 242 | llvm::timeTraceProfilerWrite(*profilerOutput); |
Anton Afanasyev | d880de2 | 2019-03-30 08:42:48 +0000 | [diff] [blame] | 243 | llvm::timeTraceProfilerCleanup(); |
| 244 | } |
| 245 | |
Dan Gohman | b37af7d | 2010-08-18 21:23:17 +0000 | [diff] [blame] | 246 | // Our error handler depends on the Diagnostics object, which we're |
| 247 | // potentially about to delete. Uninstall the handler now so that any |
| 248 | // later errors use the default handling behavior instead. |
| 249 | llvm::remove_fatal_error_handler(); |
| 250 | |
Daniel Dunbar | 30b24e9 | 2010-03-23 05:09:16 +0000 | [diff] [blame] | 251 | // When running with -disable-free, don't do any destruction or shutdown. |
| 252 | if (Clang->getFrontendOpts().DisableFree) { |
David Blaikie | 9941da4 | 2018-11-17 18:04:13 +0000 | [diff] [blame] | 253 | llvm::BuryPointer(std::move(Clang)); |
Daniel Dunbar | 30b24e9 | 2010-03-23 05:09:16 +0000 | [diff] [blame] | 254 | return !Success; |
Daniel Dunbar | f72bdf7 | 2009-12-11 22:20:12 +0000 | [diff] [blame] | 255 | } |
| 256 | |
Daniel Dunbar | 4f2bc55 | 2010-01-13 00:48:06 +0000 | [diff] [blame] | 257 | return !Success; |
Daniel Dunbar | f72bdf7 | 2009-12-11 22:20:12 +0000 | [diff] [blame] | 258 | } |