diff --git a/clang/lib/CodeGen/CodeGenAction.cpp b/clang/lib/CodeGen/CodeGenAction.cpp --- a/clang/lib/CodeGen/CodeGenAction.cpp +++ b/clang/lib/CodeGen/CodeGenAction.cpp @@ -50,6 +50,9 @@ using namespace clang; using namespace llvm; +static llvm::cl::opt ClearASTBeforeBackend("clear-clang-ast", + llvm::cl::init(true)); + namespace clang { class BackendConsumer; class ClangDiagnosticHandler final : public DiagnosticHandler { @@ -301,6 +304,11 @@ if (!getModule()) return; + // FIXME: Fix cleanup issues with clearing the AST when we properly free + // things. + if (CodeGenOpts.DisableFree && ClearASTBeforeBackend) + this->Context->getAllocator().Reset(); + LLVMContext &Ctx = getModule()->getContext(); std::unique_ptr OldDiagnosticHandler = Ctx.getDiagnosticHandler();