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(false)); + namespace clang { class BackendConsumer; class ClangDiagnosticHandler final : public DiagnosticHandler { @@ -301,6 +304,9 @@ if (!getModule()) return; + if (ClearASTBeforeBackend) + this->Context->getAllocator().Reset(); + LLVMContext &Ctx = getModule()->getContext(); std::unique_ptr OldDiagnosticHandler = Ctx.getDiagnosticHandler();