Index: include/clang/CodeGen/BackendUtil.h =================================================================== --- include/clang/CodeGen/BackendUtil.h +++ include/clang/CodeGen/BackendUtil.h @@ -37,7 +37,8 @@ void EmitBackendOutput(DiagnosticsEngine &Diags, const CodeGenOptions &CGOpts, const TargetOptions &TOpts, const LangOptions &LOpts, const llvm::DataLayout &TDesc, llvm::Module *M, - BackendAction Action, raw_pwrite_stream *OS); + BackendAction Action, + std::unique_ptr OS); void EmbedBitcode(llvm::Module *M, const CodeGenOptions &CGOpts, llvm::MemoryBufferRef Buf); Index: include/clang/CodeGen/ObjectFilePCHContainerOperations.h =================================================================== --- include/clang/CodeGen/ObjectFilePCHContainerOperations.h +++ include/clang/CodeGen/ObjectFilePCHContainerOperations.h @@ -22,10 +22,12 @@ /// Return an ASTConsumer that can be chained with a /// PCHGenerator that produces a wrapper file format /// that also contains full debug info for the module. - std::unique_ptr CreatePCHContainerGenerator( - CompilerInstance &CI, const std::string &MainFileName, - const std::string &OutputFileName, llvm::raw_pwrite_stream *OS, - std::shared_ptr Buffer) const override; + std::unique_ptr + CreatePCHContainerGenerator(CompilerInstance &CI, + const std::string &MainFileName, + const std::string &OutputFileName, + std::unique_ptr OS, + std::shared_ptr Buffer) const override; }; /// A PCHContainerReader implementation that uses LLVM to Index: include/clang/Frontend/ASTConsumers.h =================================================================== --- include/clang/Frontend/ASTConsumers.h +++ include/clang/Frontend/ASTConsumers.h @@ -31,7 +31,7 @@ // original C code. The output is intended to be in a format such that // clang could re-parse the output back into the same AST, but the // implementation is still incomplete. -std::unique_ptr CreateASTPrinter(raw_ostream *OS, +std::unique_ptr CreateASTPrinter(std::unique_ptr OS, StringRef FilterString); // AST dumper: dumps the raw AST in human-readable form to stderr; this is Index: include/clang/Frontend/CompilerInstance.h =================================================================== --- include/clang/Frontend/CompilerInstance.h +++ include/clang/Frontend/CompilerInstance.h @@ -155,15 +155,10 @@ struct OutputFile { std::string Filename; std::string TempFilename; - std::unique_ptr OS; - - OutputFile(std::string filename, std::string tempFilename, - std::unique_ptr OS) - : Filename(std::move(filename)), TempFilename(std::move(tempFilename)), - OS(std::move(OS)) {} - OutputFile(OutputFile &&O) - : Filename(std::move(O.Filename)), - TempFilename(std::move(O.TempFilename)), OS(std::move(O.OS)) {} + + OutputFile(std::string filename, std::string tempFilename) + : Filename(std::move(filename)), TempFilename(std::move(tempFilename)) { + } }; /// If the output doesn't support seeking (terminal, pipe). we switch @@ -577,8 +572,8 @@ /// \param OutFile - The output file info. void addOutputFile(OutputFile &&OutFile); - /// clearOutputFiles - Clear the output file list, destroying the contained - /// output streams. + /// clearOutputFiles - Clear the output file list. The underlying output + /// streams must have been closed beforehand. /// /// \param EraseFiles - If true, attempt to erase the files from disk. void clearOutputFiles(bool EraseFiles); @@ -685,19 +680,18 @@ /// atomically replace the target output on success). /// /// \return - Null on error. - raw_pwrite_stream *createDefaultOutputFile(bool Binary = true, - StringRef BaseInput = "", - StringRef Extension = ""); + std::unique_ptr + createDefaultOutputFile(bool Binary = true, StringRef BaseInput = "", + StringRef Extension = ""); /// Create a new output file and add it to the list of tracked output files, /// optionally deriving the output path name. /// /// \return - Null on error. - raw_pwrite_stream *createOutputFile(StringRef OutputPath, bool Binary, - bool RemoveFileOnSignal, - StringRef BaseInput, StringRef Extension, - bool UseTemporary, - bool CreateMissingDirectories = false); + std::unique_ptr + createOutputFile(StringRef OutputPath, bool Binary, bool RemoveFileOnSignal, + StringRef BaseInput, StringRef Extension, bool UseTemporary, + bool CreateMissingDirectories = false); /// Create a new output file, optionally deriving the output path name. /// @@ -731,7 +725,7 @@ bool CreateMissingDirectories, std::string *ResultPathName, std::string *TempPathName); - llvm::raw_null_ostream *createNullOutputFile(); + std::unique_ptr createNullOutputFile(); /// } /// @name Initialization Utility Methods Index: include/clang/Frontend/FrontendActions.h =================================================================== --- include/clang/Frontend/FrontendActions.h +++ include/clang/Frontend/FrontendActions.h @@ -85,7 +85,7 @@ /// create the PCHGenerator instance returned by CreateASTConsumer. /// /// \returns true if an error occurred, false otherwise. - static raw_pwrite_stream * + static std::unique_ptr ComputeASTConsumerArguments(CompilerInstance &CI, StringRef InFile, std::string &Sysroot, std::string &OutputFile); }; @@ -117,10 +117,9 @@ /// create the PCHGenerator instance returned by CreateASTConsumer. /// /// \returns true if an error occurred, false otherwise. - raw_pwrite_stream *ComputeASTConsumerArguments(CompilerInstance &CI, - StringRef InFile, - std::string &Sysroot, - std::string &OutputFile); + std::unique_ptr + ComputeASTConsumerArguments(CompilerInstance &CI, StringRef InFile, + std::string &Sysroot, std::string &OutputFile); }; class SyntaxOnlyAction : public ASTFrontendAction { Index: include/clang/Frontend/PCHContainerOperations.h =================================================================== --- include/clang/Frontend/PCHContainerOperations.h +++ include/clang/Frontend/PCHContainerOperations.h @@ -46,10 +46,12 @@ /// Return an ASTConsumer that can be chained with a /// PCHGenerator that produces a wrapper file format containing a /// serialized AST bitstream. - virtual std::unique_ptr CreatePCHContainerGenerator( - CompilerInstance &CI, const std::string &MainFileName, - const std::string &OutputFileName, llvm::raw_pwrite_stream *OS, - std::shared_ptr Buffer) const = 0; + virtual std::unique_ptr + CreatePCHContainerGenerator(CompilerInstance &CI, + const std::string &MainFileName, + const std::string &OutputFileName, + std::unique_ptr OS, + std::shared_ptr Buffer) const = 0; }; /// This abstract interface provides operations for unwrapping @@ -73,10 +75,12 @@ /// Return an ASTConsumer that can be chained with a /// PCHGenerator that writes the module to a flat file. - std::unique_ptr CreatePCHContainerGenerator( - CompilerInstance &CI, const std::string &MainFileName, - const std::string &OutputFileName, llvm::raw_pwrite_stream *OS, - std::shared_ptr Buffer) const override; + std::unique_ptr + CreatePCHContainerGenerator(CompilerInstance &CI, + const std::string &MainFileName, + const std::string &OutputFileName, + std::unique_ptr OS, + std::shared_ptr Buffer) const override; }; /// Implements read operations for a raw pass-through PCH container. Index: include/clang/Rewrite/Frontend/ASTConsumers.h =================================================================== --- include/clang/Rewrite/Frontend/ASTConsumers.h +++ include/clang/Rewrite/Frontend/ASTConsumers.h @@ -28,17 +28,18 @@ // ObjC rewriter: attempts to rewrite ObjC constructs into pure C code. // This is considered experimental, and only works with Apple's ObjC runtime. std::unique_ptr -CreateObjCRewriter(const std::string &InFile, raw_ostream *OS, +CreateObjCRewriter(const std::string &InFile, std::unique_ptr OS, DiagnosticsEngine &Diags, const LangOptions &LOpts, bool SilenceRewriteMacroWarning); std::unique_ptr -CreateModernObjCRewriter(const std::string &InFile, raw_ostream *OS, +CreateModernObjCRewriter(const std::string &InFile, + std::unique_ptr OS, DiagnosticsEngine &Diags, const LangOptions &LOpts, bool SilenceRewriteMacroWarning, bool LineInfo); /// CreateHTMLPrinter - Create an AST consumer which rewrites source code to /// HTML with syntax highlighting suitable for viewing in a web-browser. -std::unique_ptr CreateHTMLPrinter(raw_ostream *OS, +std::unique_ptr CreateHTMLPrinter(std::unique_ptr OS, Preprocessor &PP, bool SyntaxHighlight = true, bool HighlightMacros = true); Index: lib/CodeGen/BackendUtil.cpp =================================================================== --- lib/CodeGen/BackendUtil.cpp +++ lib/CodeGen/BackendUtil.cpp @@ -61,9 +61,7 @@ Timer CodeGenerationTime; - mutable legacy::PassManager *CodeGenPasses; - mutable legacy::PassManager *PerModulePasses; - mutable legacy::FunctionPassManager *PerFunctionPasses; + std::unique_ptr OS; private: TargetIRAnalysis getTargetIRAnalysis() const { @@ -73,73 +71,44 @@ return TargetIRAnalysis(); } - legacy::PassManager *getCodeGenPasses() const { - if (!CodeGenPasses) { - CodeGenPasses = new legacy::PassManager(); - CodeGenPasses->add( - createTargetTransformInfoWrapperPass(getTargetIRAnalysis())); - } - return CodeGenPasses; - } - - legacy::PassManager *getPerModulePasses() const { - if (!PerModulePasses) { - PerModulePasses = new legacy::PassManager(); - PerModulePasses->add( - createTargetTransformInfoWrapperPass(getTargetIRAnalysis())); - } - return PerModulePasses; - } - - legacy::FunctionPassManager *getPerFunctionPasses() const { - if (!PerFunctionPasses) { - PerFunctionPasses = new legacy::FunctionPassManager(TheModule); - PerFunctionPasses->add( - createTargetTransformInfoWrapperPass(getTargetIRAnalysis())); - } - return PerFunctionPasses; - } - /// Set LLVM command line options passed through -backend-option. void setCommandLineOpts(); - void CreatePasses(ModuleSummaryIndex *ModuleSummary); + void CreatePasses(legacy::PassManager &MPM, legacy::FunctionPassManager &FPM, + ModuleSummaryIndex *ModuleSummary); /// Generates the TargetMachine. - /// Returns Null if it is unable to create the target machine. + /// Leaves TM unchanged if it is unable to create the target machine. /// Some of our clang tests specify triples which are not built /// into clang. This is okay because these tests check the generated /// IR, and they require DataLayout which depends on the triple. /// In this case, we allow this method to fail and not report an error. /// When MustCreateTM is used, we print an error if we are unable to load /// the requested target. - TargetMachine *CreateTargetMachine(bool MustCreateTM); + void CreateTargetMachine(bool MustCreateTM); /// Add passes necessary to emit assembly or LLVM IR. /// /// \return True on success. - bool AddEmitPasses(BackendAction Action, raw_pwrite_stream &OS); + bool AddEmitPasses(legacy::PassManager &CodeGenPasses, BackendAction Action, + raw_pwrite_stream &OS); public: EmitAssemblyHelper(DiagnosticsEngine &_Diags, const CodeGenOptions &CGOpts, const clang::TargetOptions &TOpts, const LangOptions &LOpts, Module *M) : Diags(_Diags), CodeGenOpts(CGOpts), TargetOpts(TOpts), LangOpts(LOpts), - TheModule(M), CodeGenerationTime("Code Generation Time"), - CodeGenPasses(nullptr), PerModulePasses(nullptr), - PerFunctionPasses(nullptr) {} + TheModule(M), CodeGenerationTime("Code Generation Time") {} ~EmitAssemblyHelper() { - delete CodeGenPasses; - delete PerModulePasses; - delete PerFunctionPasses; if (CodeGenOpts.DisableFree) BuryPointer(std::move(TM)); } std::unique_ptr TM; - void EmitAssembly(BackendAction Action, raw_pwrite_stream *OS); + void EmitAssembly(BackendAction Action, + std::unique_ptr OS); }; // We need this wrapper to access LangOpts and CGOpts from extension functions @@ -305,7 +274,9 @@ MPM->add(createRewriteSymbolsPass(DL)); } -void EmitAssemblyHelper::CreatePasses(ModuleSummaryIndex *ModuleSummary) { +void EmitAssemblyHelper::CreatePasses(legacy::PassManager &MPM, + legacy::FunctionPassManager &FPM, + ModuleSummaryIndex *ModuleSummary) { if (CodeGenOpts.DisableLLVMPasses) return; @@ -356,13 +327,11 @@ PMBuilder.PrepareForLTO = CodeGenOpts.PrepareForLTO; PMBuilder.RerollLoops = CodeGenOpts.RerollLoops; - legacy::PassManager *MPM = getPerModulePasses(); - // If we are performing a ThinLTO importing compile, invoke the LTO // pipeline and pass down the in-memory module summary index. if (ModuleSummary) { PMBuilder.ModuleSummary = ModuleSummary; - PMBuilder.populateThinLTOPassManager(*MPM); + PMBuilder.populateThinLTOPassManager(MPM); return; } @@ -446,13 +415,12 @@ } // Set up the per-function pass manager. - legacy::FunctionPassManager *FPM = getPerFunctionPasses(); if (CodeGenOpts.VerifyModule) - FPM->add(createVerifierPass()); + FPM.add(createVerifierPass()); // Set up the per-module pass manager. if (!CodeGenOpts.RewriteMapFiles.empty()) - addSymbolRewriterPass(CodeGenOpts, MPM); + addSymbolRewriterPass(CodeGenOpts, &MPM); if (!CodeGenOpts.DisableGCov && (CodeGenOpts.EmitGcovArcs || CodeGenOpts.EmitGcovNotes)) { @@ -467,16 +435,16 @@ Options.FunctionNamesInData = !CodeGenOpts.CoverageNoFunctionNamesInData; Options.ExitBlockBeforeBody = CodeGenOpts.CoverageExitBlockBeforeBody; - MPM->add(createGCOVProfilerPass(Options)); + MPM.add(createGCOVProfilerPass(Options)); if (CodeGenOpts.getDebugInfo() == codegenoptions::NoDebugInfo) - MPM->add(createStripSymbolsPass(true)); + MPM.add(createStripSymbolsPass(true)); } if (CodeGenOpts.hasProfileClangInstr()) { InstrProfOptions Options; Options.NoRedZone = CodeGenOpts.DisableRedZone; Options.InstrProfileOutput = CodeGenOpts.InstrProfileOutput; - MPM->add(createInstrProfilingLegacyPass(Options)); + MPM.add(createInstrProfilingLegacyPass(Options)); } if (CodeGenOpts.hasProfileIRInstr()) { if (!CodeGenOpts.InstrProfileOutput.empty()) @@ -488,13 +456,13 @@ PMBuilder.PGOInstrUse = CodeGenOpts.ProfileInstrumentUsePath; if (!CodeGenOpts.SampleProfileFile.empty()) { - MPM->add(createSampleProfileLoaderPass(CodeGenOpts.SampleProfileFile)); + MPM.add(createSampleProfileLoaderPass(CodeGenOpts.SampleProfileFile)); PMBuilder.addExtension(PassManagerBuilder::EP_EarlyAsPossible, addInstructionCombiningPass); } - PMBuilder.populateFunctionPassManager(*FPM); - PMBuilder.populateModulePassManager(*MPM); + PMBuilder.populateFunctionPassManager(FPM); + PMBuilder.populateModulePassManager(MPM); } void EmitAssemblyHelper::setCommandLineOpts() { @@ -515,7 +483,7 @@ BackendArgs.data()); } -TargetMachine *EmitAssemblyHelper::CreateTargetMachine(bool MustCreateTM) { +void EmitAssemblyHelper::CreateTargetMachine(bool MustCreateTM) { // Create the TargetMachine for generating code. std::string Error; std::string Triple = TheModule->getTargetTriple(); @@ -523,7 +491,7 @@ if (!TheTarget) { if (MustCreateTM) Diags.Report(diag::err_fe_unable_to_create_target) << Error; - return nullptr; + return; } unsigned CodeModel = @@ -630,24 +598,18 @@ Options.MCOptions.AsmVerbose = CodeGenOpts.AsmVerbose; Options.MCOptions.ABIName = TargetOpts.ABI; - TargetMachine *TM = TheTarget->createTargetMachine(Triple, TargetOpts.CPU, - FeaturesStr, Options, - RM, CM, OptLevel); - - return TM; + TM.reset(TheTarget->createTargetMachine(Triple, TargetOpts.CPU, FeaturesStr, + Options, RM, CM, OptLevel)); } -bool EmitAssemblyHelper::AddEmitPasses(BackendAction Action, +bool EmitAssemblyHelper::AddEmitPasses(legacy::PassManager &CodeGenPasses, + BackendAction Action, raw_pwrite_stream &OS) { - - // Create the code generator passes. - legacy::PassManager *PM = getCodeGenPasses(); - // Add LibraryInfo. llvm::Triple TargetTriple(TheModule->getTargetTriple()); std::unique_ptr TLII( createTLII(TargetTriple, CodeGenOpts)); - PM->add(new TargetLibraryInfoWrapperPass(*TLII)); + CodeGenPasses.add(new TargetLibraryInfoWrapperPass(*TLII)); // Normal mode, emit a .s or .o file by running the code generator. Note, // this also adds codegenerator level optimization passes. @@ -663,9 +625,9 @@ // "codegen" passes so that it isn't run multiple times when there is // inlining happening. if (CodeGenOpts.OptimizationLevel > 0) - PM->add(createObjCARCContractPass()); + CodeGenPasses.add(createObjCARCContractPass()); - if (TM->addPassesToEmitFile(*PM, OS, CGFT, + if (TM->addPassesToEmitFile(CodeGenPasses, OS, CGFT, /*DisableVerify=*/!CodeGenOpts.VerifyModule)) { Diags.Report(diag::err_fe_unable_to_interface_with_target); return false; @@ -675,7 +637,7 @@ } void EmitAssemblyHelper::EmitAssembly(BackendAction Action, - raw_pwrite_stream *OS) { + std::unique_ptr OS) { TimeRegion Region(llvm::TimePassesIsEnabled ? &CodeGenerationTime : nullptr); setCommandLineOpts(); @@ -683,8 +645,7 @@ bool UsesCodeGen = (Action != Backend_EmitNothing && Action != Backend_EmitBC && Action != Backend_EmitLL); - if (!TM) - TM.reset(CreateTargetMachine(UsesCodeGen)); + CreateTargetMachine(UsesCodeGen); if (UsesCodeGen && !TM) return; @@ -711,25 +672,37 @@ assert(ModuleSummary && "Expected non-empty module summary index"); } - CreatePasses(ModuleSummary.get()); + legacy::PassManager PerModulePasses; + PerModulePasses.add( + createTargetTransformInfoWrapperPass(getTargetIRAnalysis())); + + legacy::FunctionPassManager PerFunctionPasses(TheModule); + PerFunctionPasses.add( + createTargetTransformInfoWrapperPass(getTargetIRAnalysis())); + + CreatePasses(PerModulePasses, PerFunctionPasses, ModuleSummary.get()); + + legacy::PassManager CodeGenPasses; + CodeGenPasses.add( + createTargetTransformInfoWrapperPass(getTargetIRAnalysis())); switch (Action) { case Backend_EmitNothing: break; case Backend_EmitBC: - getPerModulePasses()->add(createBitcodeWriterPass( + PerModulePasses.add(createBitcodeWriterPass( *OS, CodeGenOpts.EmitLLVMUseLists, CodeGenOpts.EmitSummaryIndex, CodeGenOpts.EmitSummaryIndex)); break; case Backend_EmitLL: - getPerModulePasses()->add( + PerModulePasses.add( createPrintModulePass(*OS, "", CodeGenOpts.EmitLLVMUseLists)); break; default: - if (!AddEmitPasses(Action, *OS)) + if (!AddEmitPasses(CodeGenPasses, Action, *OS)) return; } @@ -739,24 +712,24 @@ // Run passes. For now we do all passes at once, but eventually we // would like to have the option of streaming code generation. - if (PerFunctionPasses) { + { PrettyStackTraceString CrashInfo("Per-function optimization"); - PerFunctionPasses->doInitialization(); + PerFunctionPasses.doInitialization(); for (Function &F : *TheModule) if (!F.isDeclaration()) - PerFunctionPasses->run(F); - PerFunctionPasses->doFinalization(); + PerFunctionPasses.run(F); + PerFunctionPasses.doFinalization(); } - if (PerModulePasses) { + { PrettyStackTraceString CrashInfo("Per-module optimization passes"); - PerModulePasses->run(*TheModule); + PerModulePasses.run(*TheModule); } - if (CodeGenPasses) { + { PrettyStackTraceString CrashInfo("Code generation"); - CodeGenPasses->run(*TheModule); + CodeGenPasses.run(*TheModule); } } @@ -765,10 +738,10 @@ const clang::TargetOptions &TOpts, const LangOptions &LOpts, const llvm::DataLayout &TDesc, Module *M, BackendAction Action, - raw_pwrite_stream *OS) { + std::unique_ptr OS) { EmitAssemblyHelper AsmHelper(Diags, CGOpts, TOpts, LOpts, M); - AsmHelper.EmitAssembly(Action, OS); + AsmHelper.EmitAssembly(Action, std::move(OS)); // Verify clang's TargetInfo DataLayout against the LLVM TargetMachine's // DataLayout. Index: lib/CodeGen/CodeGenAction.cpp =================================================================== --- lib/CodeGen/CodeGenAction.cpp +++ lib/CodeGen/CodeGenAction.cpp @@ -46,7 +46,7 @@ const CodeGenOptions &CodeGenOpts; const TargetOptions &TargetOpts; const LangOptions &LangOpts; - raw_pwrite_stream *AsmOutStream; + std::unique_ptr AsmOutStream; ASTContext *Context; Timer LLVMIRGeneration; @@ -68,11 +68,12 @@ const TargetOptions &TargetOpts, const LangOptions &LangOpts, bool TimePasses, const std::string &InFile, const SmallVectorImpl> &LinkModules, - raw_pwrite_stream *OS, LLVMContext &C, + std::unique_ptr OS, LLVMContext &C, CoverageSourceInfo *CoverageInfo = nullptr) : Diags(Diags), Action(Action), CodeGenOpts(CodeGenOpts), - TargetOpts(TargetOpts), LangOpts(LangOpts), AsmOutStream(OS), - Context(nullptr), LLVMIRGeneration("LLVM IR Generation Time"), + TargetOpts(TargetOpts), LangOpts(LangOpts), + AsmOutStream(std::move(OS)), Context(nullptr), + LLVMIRGeneration("LLVM IR Generation Time"), Gen(CreateLLVMCodeGen(Diags, InFile, HeaderSearchOpts, PPOpts, CodeGenOpts, C, CoverageInfo)) { llvm::TimePassesIsEnabled = TimePasses; @@ -177,7 +178,7 @@ EmitBackendOutput(Diags, CodeGenOpts, TargetOpts, LangOpts, C.getTargetInfo().getDataLayout(), - getModule(), Action, AsmOutStream); + getModule(), Action, std::move(AsmOutStream)); Ctx.setInlineAsmDiagnosticHandler(OldHandler, OldContext); @@ -691,7 +692,7 @@ return VMContext; } -static raw_pwrite_stream * +static std::unique_ptr GetOutputStream(CompilerInstance &CI, StringRef InFile, BackendAction Action) { switch (Action) { case Backend_EmitAssembly: @@ -701,7 +702,7 @@ case Backend_EmitBC: return CI.createDefaultOutputFile(true, InFile, "bc"); case Backend_EmitNothing: - return nullptr; + return {}; case Backend_EmitMCNull: return CI.createNullOutputFile(); case Backend_EmitObj: @@ -714,7 +715,7 @@ std::unique_ptr CodeGenAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) { BackendAction BA = static_cast(Act); - raw_pwrite_stream *OS = GetOutputStream(CI, InFile, BA); + std::unique_ptr OS = GetOutputStream(CI, InFile, BA); if (BA != Backend_EmitNothing && !OS) return nullptr; @@ -754,7 +755,7 @@ BA, CI.getDiagnostics(), CI.getHeaderSearchOpts(), CI.getPreprocessorOpts(), CI.getCodeGenOpts(), CI.getTargetOpts(), CI.getLangOpts(), CI.getFrontendOpts().ShowTimers, InFile, LinkModules, - OS, *VMContext, CoverageInfo)); + std::move(OS), *VMContext, CoverageInfo)); BEConsumer = Result.get(); return std::move(Result); } @@ -786,7 +787,8 @@ if (getCurrentFileKind() == IK_LLVM_IR) { BackendAction BA = static_cast(Act); CompilerInstance &CI = getCompilerInstance(); - raw_pwrite_stream *OS = GetOutputStream(CI, getCurrentFile(), BA); + std::unique_ptr OS = + GetOutputStream(CI, getCurrentFile(), BA); if (BA != Backend_EmitNothing && !OS) return; @@ -843,7 +845,7 @@ EmitBackendOutput(CI.getDiagnostics(), CI.getCodeGenOpts(), TargetOpts, CI.getLangOpts(), CI.getTarget().getDataLayout(), - TheModule.get(), BA, OS); + TheModule.get(), BA, std::move(OS)); return; } Index: lib/CodeGen/ObjectFilePCHContainerOperations.cpp =================================================================== --- lib/CodeGen/ObjectFilePCHContainerOperations.cpp +++ lib/CodeGen/ObjectFilePCHContainerOperations.cpp @@ -55,7 +55,7 @@ std::unique_ptr VMContext; std::unique_ptr M; std::unique_ptr Builder; - raw_pwrite_stream *OS; + std::unique_ptr OS; std::shared_ptr Buffer; /// Visit every type and emit debug info for it. @@ -138,15 +138,15 @@ public: PCHContainerGenerator(CompilerInstance &CI, const std::string &MainFileName, const std::string &OutputFileName, - raw_pwrite_stream *OS, + std::unique_ptr OS, std::shared_ptr Buffer) : Diags(CI.getDiagnostics()), MainFileName(MainFileName), OutputFileName(OutputFileName), Ctx(nullptr), MMap(CI.getPreprocessor().getHeaderSearchInfo().getModuleMap()), HeaderSearchOpts(CI.getHeaderSearchOpts()), PreprocessorOpts(CI.getPreprocessorOpts()), - TargetOpts(CI.getTargetOpts()), LangOpts(CI.getLangOpts()), OS(OS), - Buffer(std::move(Buffer)) { + TargetOpts(CI.getTargetOpts()), LangOpts(CI.getLangOpts()), + OS(std::move(OS)), Buffer(std::move(Buffer)) { // The debug info output isn't affected by CodeModel and // ThreadModel, but the backend expects them to be nonempty. CodeGenOpts.CodeModel = "default"; @@ -281,20 +281,18 @@ DEBUG({ // Print the IR for the PCH container to the debug output. llvm::SmallString<0> Buffer; - llvm::raw_svector_ostream OS(Buffer); - clang::EmitBackendOutput(Diags, CodeGenOpts, TargetOpts, LangOpts, - Ctx.getTargetInfo().getDataLayout(), M.get(), - BackendAction::Backend_EmitLL, &OS); + clang::EmitBackendOutput( + Diags, CodeGenOpts, TargetOpts, LangOpts, + Ctx.getTargetInfo().getDataLayout(), M.get(), + BackendAction::Backend_EmitLL, + llvm::make_unique(Buffer)); llvm::dbgs() << Buffer; }); // Use the LLVM backend to emit the pch container. clang::EmitBackendOutput(Diags, CodeGenOpts, TargetOpts, LangOpts, Ctx.getTargetInfo().getDataLayout(), M.get(), - BackendAction::Backend_EmitObj, OS); - - // Make sure the pch container hits disk. - OS->flush(); + BackendAction::Backend_EmitObj, std::move(OS)); // Free the memory for the temporary buffer. llvm::SmallVector Empty; @@ -307,10 +305,11 @@ std::unique_ptr ObjectFilePCHContainerWriter::CreatePCHContainerGenerator( CompilerInstance &CI, const std::string &MainFileName, - const std::string &OutputFileName, llvm::raw_pwrite_stream *OS, + const std::string &OutputFileName, + std::unique_ptr OS, std::shared_ptr Buffer) const { - return llvm::make_unique(CI, MainFileName, - OutputFileName, OS, Buffer); + return llvm::make_unique( + CI, MainFileName, OutputFileName, std::move(OS), Buffer); } void ObjectFilePCHContainerReader::ExtractPCH( Index: lib/Frontend/ASTConsumers.cpp =================================================================== --- lib/Frontend/ASTConsumers.cpp +++ lib/Frontend/ASTConsumers.cpp @@ -35,9 +35,9 @@ typedef RecursiveASTVisitor base; public: - ASTPrinter(raw_ostream *Out = nullptr, bool Dump = false, + ASTPrinter(std::unique_ptr Out = nullptr, bool Dump = false, StringRef FilterString = "", bool DumpLookups = false) - : Out(Out ? *Out : llvm::outs()), Dump(Dump), + : Out(Out ? *Out : llvm::outs()), OwnedOut(std::move(Out)), Dump(Dump), FilterString(FilterString), DumpLookups(DumpLookups) {} void HandleTranslationUnit(ASTContext &Context) override { @@ -94,6 +94,7 @@ } raw_ostream &Out; + std::unique_ptr OwnedOut; bool Dump; std::string FilterString; bool DumpLookups; @@ -122,9 +123,11 @@ }; } // end anonymous namespace -std::unique_ptr clang::CreateASTPrinter(raw_ostream *Out, - StringRef FilterString) { - return llvm::make_unique(Out, /*Dump=*/false, FilterString); +std::unique_ptr +clang::CreateASTPrinter(std::unique_ptr Out, + StringRef FilterString) { + return llvm::make_unique(std::move(Out), /*Dump=*/false, + FilterString); } std::unique_ptr clang::CreateASTDumper(StringRef FilterString, Index: lib/Frontend/ASTUnit.cpp =================================================================== --- lib/Frontend/ASTUnit.cpp +++ lib/Frontend/ASTUnit.cpp @@ -920,17 +920,17 @@ unsigned &Hash; std::vector TopLevelDecls; PrecompilePreambleAction *Action; - raw_ostream *Out; + std::unique_ptr Out; public: PrecompilePreambleConsumer(ASTUnit &Unit, PrecompilePreambleAction *Action, const Preprocessor &PP, StringRef isysroot, - raw_ostream *Out) + std::unique_ptr Out) : PCHGenerator(PP, "", nullptr, isysroot, std::make_shared(), ArrayRef>(), /*AllowASTWithErrors=*/true), Unit(Unit), Hash(Unit.getCurrentTopLevelHashValue()), Action(Action), - Out(Out) { + Out(std::move(Out)) { Hash = 0; } @@ -982,8 +982,9 @@ StringRef InFile) { std::string Sysroot; std::string OutputFile; - raw_ostream *OS = GeneratePCHAction::ComputeASTConsumerArguments( - CI, InFile, Sysroot, OutputFile); + std::unique_ptr OS = + GeneratePCHAction::ComputeASTConsumerArguments(CI, InFile, Sysroot, + OutputFile); if (!OS) return nullptr; @@ -994,7 +995,7 @@ llvm::make_unique( Unit.getCurrentTopLevelHashValue())); return llvm::make_unique( - Unit, this, CI.getPreprocessor(), Sysroot, OS); + Unit, this, CI.getPreprocessor(), Sysroot, std::move(OS)); } static bool isNonDriverDiag(const StoredDiagnostic &StoredDiag) { Index: lib/Frontend/CompilerInstance.cpp =================================================================== --- lib/Frontend/CompilerInstance.cpp +++ lib/Frontend/CompilerInstance.cpp @@ -542,15 +542,11 @@ // Output Files void CompilerInstance::addOutputFile(OutputFile &&OutFile) { - assert(OutFile.OS && "Attempt to add empty stream to output list!"); OutputFiles.push_back(std::move(OutFile)); } void CompilerInstance::clearOutputFiles(bool EraseFiles) { for (OutputFile &OF : OutputFiles) { - // Manually close the stream before we rename it. - OF.OS.reset(); - if (!OF.TempFilename.empty()) { if (EraseFiles) { llvm::sys::fs::remove(OF.TempFilename); @@ -570,13 +566,12 @@ } } else if (!OF.Filename.empty() && EraseFiles) llvm::sys::fs::remove(OF.Filename); - } OutputFiles.clear(); NonSeekStream.reset(); } -raw_pwrite_stream * +std::unique_ptr CompilerInstance::createDefaultOutputFile(bool Binary, StringRef InFile, StringRef Extension) { return createOutputFile(getFrontendOpts().OutputFile, Binary, @@ -584,14 +579,11 @@ /*UseTemporary=*/true); } -llvm::raw_null_ostream *CompilerInstance::createNullOutputFile() { - auto OS = llvm::make_unique(); - llvm::raw_null_ostream *Ret = OS.get(); - addOutputFile(OutputFile("", "", std::move(OS))); - return Ret; +std::unique_ptr CompilerInstance::createNullOutputFile() { + return llvm::make_unique(); } -raw_pwrite_stream * +std::unique_ptr CompilerInstance::createOutputFile(StringRef OutputPath, bool Binary, bool RemoveFileOnSignal, StringRef InFile, StringRef Extension, bool UseTemporary, @@ -604,16 +596,15 @@ if (!OS) { getDiagnostics().Report(diag::err_fe_unable_to_open_output) << OutputPath << EC.message(); - return nullptr; + return {}; } - raw_pwrite_stream *Ret = OS.get(); // Add the output file -- but don't try to remove "-", since this means we are // using stdin. - addOutputFile(OutputFile((OutputPathName != "-") ? OutputPathName : "", - TempPathName, std::move(OS))); + addOutputFile( + OutputFile((OutputPathName != "-") ? OutputPathName : "", TempPathName)); - return Ret; + return OS; } std::unique_ptr CompilerInstance::createOutputFile( Index: lib/Frontend/FrontendActions.cpp =================================================================== --- lib/Frontend/FrontendActions.cpp +++ lib/Frontend/FrontendActions.cpp @@ -48,8 +48,9 @@ std::unique_ptr ASTPrintAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) { - if (raw_ostream *OS = CI.createDefaultOutputFile(false, InFile)) - return CreateASTPrinter(OS, CI.getFrontendOpts().ASTDumpFilter); + if (std::unique_ptr OS = + CI.createDefaultOutputFile(false, InFile)) + return CreateASTPrinter(std::move(OS), CI.getFrontendOpts().ASTDumpFilter); return nullptr; } @@ -80,7 +81,7 @@ GeneratePCHAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) { std::string Sysroot; std::string OutputFile; - raw_pwrite_stream *OS = + std::unique_ptr OS = ComputeASTConsumerArguments(CI, InFile, Sysroot, OutputFile); if (!OS) return nullptr; @@ -94,14 +95,16 @@ CI.getPreprocessor(), OutputFile, nullptr, Sysroot, Buffer, CI.getFrontendOpts().ModuleFileExtensions)); Consumers.push_back(CI.getPCHContainerWriter().CreatePCHContainerGenerator( - CI, InFile, OutputFile, OS, Buffer)); + CI, InFile, OutputFile, std::move(OS), Buffer)); return llvm::make_unique(std::move(Consumers)); } -raw_pwrite_stream *GeneratePCHAction::ComputeASTConsumerArguments( - CompilerInstance &CI, StringRef InFile, std::string &Sysroot, - std::string &OutputFile) { +std::unique_ptr +GeneratePCHAction::ComputeASTConsumerArguments(CompilerInstance &CI, + StringRef InFile, + std::string &Sysroot, + std::string &OutputFile) { Sysroot = CI.getHeaderSearchOpts().Sysroot; if (CI.getFrontendOpts().RelocatablePCH && Sysroot.empty()) { CI.getDiagnostics().Report(diag::err_relocatable_without_isysroot); @@ -111,7 +114,7 @@ // We use createOutputFile here because this is exposed via libclang, and we // must disable the RemoveFileOnSignal behavior. // We use a temporary to avoid race conditions. - raw_pwrite_stream *OS = + std::unique_ptr OS = CI.createOutputFile(CI.getFrontendOpts().OutputFile, /*Binary=*/true, /*RemoveFileOnSignal=*/false, InFile, /*Extension=*/"", /*useTemporary=*/true); @@ -127,7 +130,7 @@ StringRef InFile) { std::string Sysroot; std::string OutputFile; - raw_pwrite_stream *OS = + std::unique_ptr OS = ComputeASTConsumerArguments(CI, InFile, Sysroot, OutputFile); if (!OS) return nullptr; @@ -142,7 +145,7 @@ /*IncludeTimestamps=*/ +CI.getFrontendOpts().BuildingImplicitModule)); Consumers.push_back(CI.getPCHContainerWriter().CreatePCHContainerGenerator( - CI, InFile, OutputFile, OS, Buffer)); + CI, InFile, OutputFile, std::move(OS), Buffer)); return llvm::make_unique(std::move(Consumers)); } @@ -375,9 +378,11 @@ return true; } -raw_pwrite_stream *GenerateModuleAction::ComputeASTConsumerArguments( - CompilerInstance &CI, StringRef InFile, std::string &Sysroot, - std::string &OutputFile) { +std::unique_ptr +GenerateModuleAction::ComputeASTConsumerArguments(CompilerInstance &CI, + StringRef InFile, + std::string &Sysroot, + std::string &OutputFile) { // If no output file was provided, figure out where this module would go // in the module cache. if (CI.getFrontendOpts().OutputFile.empty()) { @@ -390,7 +395,7 @@ // We use createOutputFile here because this is exposed via libclang, and we // must disable the RemoveFileOnSignal behavior. // We use a temporary to avoid race conditions. - raw_pwrite_stream *OS = + std::unique_ptr OS = CI.createOutputFile(CI.getFrontendOpts().OutputFile, /*Binary=*/true, /*RemoveFileOnSignal=*/false, InFile, /*Extension=*/"", /*useTemporary=*/true, @@ -644,11 +649,12 @@ void GeneratePTHAction::ExecuteAction() { CompilerInstance &CI = getCompilerInstance(); - raw_pwrite_stream *OS = CI.createDefaultOutputFile(true, getCurrentFile()); + std::unique_ptr OS = + CI.createDefaultOutputFile(true, getCurrentFile()); if (!OS) return; - CacheTokens(CI.getPreprocessor(), OS); + CacheTokens(CI.getPreprocessor(), OS.get()); } void PreprocessOnlyAction::ExecuteAction() { @@ -709,10 +715,11 @@ } } - raw_ostream *OS = CI.createDefaultOutputFile(BinaryMode, getCurrentFile()); + std::unique_ptr OS = + CI.createDefaultOutputFile(BinaryMode, getCurrentFile()); if (!OS) return; - DoPrintPreprocessedInput(CI.getPreprocessor(), OS, + DoPrintPreprocessedInput(CI.getPreprocessor(), OS.get(), CI.getPreprocessorOutputOpts()); } Index: lib/Frontend/PCHContainerOperations.cpp =================================================================== --- lib/Frontend/PCHContainerOperations.cpp +++ lib/Frontend/PCHContainerOperations.cpp @@ -28,12 +28,12 @@ /// \brief A PCHContainerGenerator that writes out the PCH to a flat file. class RawPCHContainerGenerator : public ASTConsumer { std::shared_ptr Buffer; - raw_pwrite_stream *OS; + std::unique_ptr OS; public: - RawPCHContainerGenerator(llvm::raw_pwrite_stream *OS, + RawPCHContainerGenerator(std::unique_ptr OS, std::shared_ptr Buffer) - : Buffer(std::move(Buffer)), OS(OS) {} + : Buffer(std::move(Buffer)), OS(std::move(OS)) {} ~RawPCHContainerGenerator() override = default; @@ -53,9 +53,9 @@ std::unique_ptr RawPCHContainerWriter::CreatePCHContainerGenerator( CompilerInstance &CI, const std::string &MainFileName, - const std::string &OutputFileName, llvm::raw_pwrite_stream *OS, + const std::string &OutputFileName, std::unique_ptr OS, std::shared_ptr Buffer) const { - return llvm::make_unique(OS, Buffer); + return llvm::make_unique(std::move(OS), Buffer); } void RawPCHContainerReader::ExtractPCH( Index: lib/Frontend/Rewrite/FrontendActions.cpp =================================================================== --- lib/Frontend/Rewrite/FrontendActions.cpp +++ lib/Frontend/Rewrite/FrontendActions.cpp @@ -33,8 +33,9 @@ std::unique_ptr HTMLPrintAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) { - if (raw_ostream *OS = CI.createDefaultOutputFile(false, InFile)) - return CreateHTMLPrinter(OS, CI.getPreprocessor()); + if (std::unique_ptr OS = + CI.createDefaultOutputFile(false, InFile)) + return CreateHTMLPrinter(std::move(OS), CI.getPreprocessor()); return nullptr; } @@ -152,14 +153,15 @@ std::unique_ptr RewriteObjCAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) { - if (raw_ostream *OS = CI.createDefaultOutputFile(false, InFile, "cpp")) { + if (std::unique_ptr OS = + CI.createDefaultOutputFile(false, InFile, "cpp")) { if (CI.getLangOpts().ObjCRuntime.isNonFragile()) return CreateModernObjCRewriter( - InFile, OS, CI.getDiagnostics(), CI.getLangOpts(), + InFile, std::move(OS), CI.getDiagnostics(), CI.getLangOpts(), CI.getDiagnosticOpts().NoRewriteMacros, (CI.getCodeGenOpts().getDebugInfo() != codegenoptions::NoDebugInfo)); - return CreateObjCRewriter(InFile, OS, - CI.getDiagnostics(), CI.getLangOpts(), + return CreateObjCRewriter(InFile, std::move(OS), CI.getDiagnostics(), + CI.getLangOpts(), CI.getDiagnosticOpts().NoRewriteMacros); } return nullptr; @@ -173,25 +175,28 @@ void RewriteMacrosAction::ExecuteAction() { CompilerInstance &CI = getCompilerInstance(); - raw_ostream *OS = CI.createDefaultOutputFile(true, getCurrentFile()); + std::unique_ptr OS = + CI.createDefaultOutputFile(true, getCurrentFile()); if (!OS) return; - RewriteMacrosInInput(CI.getPreprocessor(), OS); + RewriteMacrosInInput(CI.getPreprocessor(), OS.get()); } void RewriteTestAction::ExecuteAction() { CompilerInstance &CI = getCompilerInstance(); - raw_ostream *OS = CI.createDefaultOutputFile(false, getCurrentFile()); + std::unique_ptr OS = + CI.createDefaultOutputFile(false, getCurrentFile()); if (!OS) return; - DoRewriteTest(CI.getPreprocessor(), OS); + DoRewriteTest(CI.getPreprocessor(), OS.get()); } void RewriteIncludesAction::ExecuteAction() { CompilerInstance &CI = getCompilerInstance(); - raw_ostream *OS = CI.createDefaultOutputFile(true, getCurrentFile()); + std::unique_ptr OS = + CI.createDefaultOutputFile(true, getCurrentFile()); if (!OS) return; - RewriteIncludesInInput(CI.getPreprocessor(), OS, + RewriteIncludesInInput(CI.getPreprocessor(), OS.get(), CI.getPreprocessorOutputOpts()); } Index: lib/Frontend/Rewrite/HTMLPrint.cpp =================================================================== --- lib/Frontend/Rewrite/HTMLPrint.cpp +++ lib/Frontend/Rewrite/HTMLPrint.cpp @@ -32,14 +32,14 @@ namespace { class HTMLPrinter : public ASTConsumer { Rewriter R; - raw_ostream *Out; + std::unique_ptr Out; Preprocessor &PP; bool SyntaxHighlight, HighlightMacros; public: - HTMLPrinter(raw_ostream *OS, Preprocessor &pp, + HTMLPrinter(std::unique_ptr OS, Preprocessor &pp, bool _SyntaxHighlight, bool _HighlightMacros) - : Out(OS), PP(pp), SyntaxHighlight(_SyntaxHighlight), + : Out(std::move(OS)), PP(pp), SyntaxHighlight(_SyntaxHighlight), HighlightMacros(_HighlightMacros) {} void Initialize(ASTContext &context) override; @@ -47,11 +47,10 @@ }; } -std::unique_ptr clang::CreateHTMLPrinter(raw_ostream *OS, - Preprocessor &PP, - bool SyntaxHighlight, - bool HighlightMacros) { - return llvm::make_unique(OS, PP, SyntaxHighlight, +std::unique_ptr +clang::CreateHTMLPrinter(std::unique_ptr OS, Preprocessor &PP, + bool SyntaxHighlight, bool HighlightMacros) { + return llvm::make_unique(std::move(OS), PP, SyntaxHighlight, HighlightMacros); } Index: lib/Frontend/Rewrite/RewriteModernObjC.cpp =================================================================== --- lib/Frontend/Rewrite/RewriteModernObjC.cpp +++ lib/Frontend/Rewrite/RewriteModernObjC.cpp @@ -72,7 +72,7 @@ Stmt *CurrentBody; ParentMap *PropParentMap; // created lazily. std::string InFileName; - raw_ostream* OutFile; + std::unique_ptr OutFile; std::string Preamble; TypeDecl *ProtocolTypeDecl; @@ -239,9 +239,9 @@ void HandleTopLevelSingleDecl(Decl *D); void HandleDeclInMainFile(Decl *D); - RewriteModernObjC(std::string inFile, raw_ostream *OS, - DiagnosticsEngine &D, const LangOptions &LOpts, - bool silenceMacroWarn, bool LineInfo); + RewriteModernObjC(std::string inFile, std::unique_ptr OS, + DiagnosticsEngine &D, const LangOptions &LOpts, + bool silenceMacroWarn, bool LineInfo); ~RewriteModernObjC() override {} @@ -643,12 +643,13 @@ return Ext == "h" || Ext == "hh" || Ext == "H"; } -RewriteModernObjC::RewriteModernObjC(std::string inFile, raw_ostream* OS, - DiagnosticsEngine &D, const LangOptions &LOpts, - bool silenceMacroWarn, - bool LineInfo) - : Diags(D), LangOpts(LOpts), InFileName(inFile), OutFile(OS), - SilenceRewriteMacroWarning(silenceMacroWarn), GenerateLineInfo(LineInfo) { +RewriteModernObjC::RewriteModernObjC(std::string inFile, + std::unique_ptr OS, + DiagnosticsEngine &D, + const LangOptions &LOpts, + bool silenceMacroWarn, bool LineInfo) + : Diags(D), LangOpts(LOpts), InFileName(inFile), OutFile(std::move(OS)), + SilenceRewriteMacroWarning(silenceMacroWarn), GenerateLineInfo(LineInfo) { IsHeader = IsHeaderFile(inFile); RewriteFailedDiag = Diags.getCustomDiagID(DiagnosticsEngine::Warning, "rewriting sub-expression within a macro (may not be correct)"); @@ -664,10 +665,12 @@ } std::unique_ptr clang::CreateModernObjCRewriter( - const std::string &InFile, raw_ostream *OS, DiagnosticsEngine &Diags, - const LangOptions &LOpts, bool SilenceRewriteMacroWarning, bool LineInfo) { - return llvm::make_unique( - InFile, OS, Diags, LOpts, SilenceRewriteMacroWarning, LineInfo); + const std::string &InFile, std::unique_ptr OS, + DiagnosticsEngine &Diags, const LangOptions &LOpts, + bool SilenceRewriteMacroWarning, bool LineInfo) { + return llvm::make_unique(InFile, std::move(OS), Diags, + LOpts, SilenceRewriteMacroWarning, + LineInfo); } void RewriteModernObjC::InitializeCommon(ASTContext &context) { Index: lib/Frontend/Rewrite/RewriteObjC.cpp =================================================================== --- lib/Frontend/Rewrite/RewriteObjC.cpp +++ lib/Frontend/Rewrite/RewriteObjC.cpp @@ -71,7 +71,7 @@ Stmt *CurrentBody; ParentMap *PropParentMap; // created lazily. std::string InFileName; - raw_ostream* OutFile; + std::unique_ptr OutFile; std::string Preamble; TypeDecl *ProtocolTypeDecl; @@ -190,7 +190,7 @@ void HandleTopLevelSingleDecl(Decl *D); void HandleDeclInMainFile(Decl *D); - RewriteObjC(std::string inFile, raw_ostream *OS, + RewriteObjC(std::string inFile, std::unique_ptr OS, DiagnosticsEngine &D, const LangOptions &LOpts, bool silenceMacroWarn); @@ -506,11 +506,10 @@ class RewriteObjCFragileABI : public RewriteObjC { public: - RewriteObjCFragileABI(std::string inFile, raw_ostream *OS, - DiagnosticsEngine &D, const LangOptions &LOpts, - bool silenceMacroWarn) : RewriteObjC(inFile, OS, - D, LOpts, - silenceMacroWarn) {} + RewriteObjCFragileABI(std::string inFile, std::unique_ptr OS, + DiagnosticsEngine &D, const LangOptions &LOpts, + bool silenceMacroWarn) + : RewriteObjC(inFile, std::move(OS), D, LOpts, silenceMacroWarn) {} ~RewriteObjCFragileABI() override {} void Initialize(ASTContext &context) override; @@ -575,11 +574,11 @@ return Ext == "h" || Ext == "hh" || Ext == "H"; } -RewriteObjC::RewriteObjC(std::string inFile, raw_ostream* OS, +RewriteObjC::RewriteObjC(std::string inFile, std::unique_ptr OS, DiagnosticsEngine &D, const LangOptions &LOpts, bool silenceMacroWarn) - : Diags(D), LangOpts(LOpts), InFileName(inFile), OutFile(OS), - SilenceRewriteMacroWarning(silenceMacroWarn) { + : Diags(D), LangOpts(LOpts), InFileName(inFile), OutFile(std::move(OS)), + SilenceRewriteMacroWarning(silenceMacroWarn) { IsHeader = IsHeaderFile(inFile); RewriteFailedDiag = Diags.getCustomDiagID(DiagnosticsEngine::Warning, "rewriting sub-expression within a macro (may not be correct)"); @@ -590,11 +589,12 @@ } std::unique_ptr -clang::CreateObjCRewriter(const std::string &InFile, raw_ostream *OS, +clang::CreateObjCRewriter(const std::string &InFile, + std::unique_ptr OS, DiagnosticsEngine &Diags, const LangOptions &LOpts, bool SilenceRewriteMacroWarning) { - return llvm::make_unique(InFile, OS, Diags, LOpts, - SilenceRewriteMacroWarning); + return llvm::make_unique( + InFile, std::move(OS), Diags, LOpts, SilenceRewriteMacroWarning); } void RewriteObjC::InitializeCommon(ASTContext &context) { Index: tools/clang-check/ClangCheck.cpp =================================================================== --- tools/clang-check/ClangCheck.cpp +++ tools/clang-check/ClangCheck.cpp @@ -142,7 +142,7 @@ return clang::CreateASTDumper(ASTDumpFilter, /*DumpDecls=*/true, /*DumpLookups=*/false); if (ASTPrint) - return clang::CreateASTPrinter(&llvm::outs(), ASTDumpFilter); + return clang::CreateASTPrinter(nullptr, ASTDumpFilter); return llvm::make_unique(); } };