Re: [PATCH] D21537: Frontend: Simplify ownership model for clang's output streams.
This revision was automatically updated to reflect the committed changes. Closed by commit rL275507: Frontend: Simplify ownership model for clang's output streams. (authored by pcc). Changed prior to commit: https://reviews.llvm.org/D21537?vs=61317=64071#toc Repository: rL LLVM https://reviews.llvm.org/D21537 Files: cfe/trunk/include/clang/CodeGen/BackendUtil.h cfe/trunk/include/clang/CodeGen/ObjectFilePCHContainerOperations.h cfe/trunk/include/clang/Frontend/ASTConsumers.h cfe/trunk/include/clang/Frontend/CompilerInstance.h cfe/trunk/include/clang/Frontend/FrontendActions.h cfe/trunk/include/clang/Frontend/PCHContainerOperations.h cfe/trunk/include/clang/Rewrite/Frontend/ASTConsumers.h cfe/trunk/lib/CodeGen/BackendUtil.cpp cfe/trunk/lib/CodeGen/CodeGenAction.cpp cfe/trunk/lib/CodeGen/ObjectFilePCHContainerOperations.cpp cfe/trunk/lib/Frontend/ASTConsumers.cpp cfe/trunk/lib/Frontend/ASTUnit.cpp cfe/trunk/lib/Frontend/CompilerInstance.cpp cfe/trunk/lib/Frontend/FrontendActions.cpp cfe/trunk/lib/Frontend/PCHContainerOperations.cpp cfe/trunk/lib/Frontend/Rewrite/FrontendActions.cpp cfe/trunk/lib/Frontend/Rewrite/HTMLPrint.cpp cfe/trunk/lib/Frontend/Rewrite/RewriteModernObjC.cpp cfe/trunk/lib/Frontend/Rewrite/RewriteObjC.cpp cfe/trunk/tools/clang-check/ClangCheck.cpp Index: cfe/trunk/lib/Frontend/Rewrite/RewriteObjC.cpp === --- cfe/trunk/lib/Frontend/Rewrite/RewriteObjC.cpp +++ cfe/trunk/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 , const LangOptions , bool silenceMacroWarn); @@ -506,11 +506,10 @@ class RewriteObjCFragileABI : public RewriteObjC { public: -RewriteObjCFragileABI(std::string inFile, raw_ostream *OS, -DiagnosticsEngine , const LangOptions , -bool silenceMacroWarn) : RewriteObjC(inFile, OS, - D, LOpts, - silenceMacroWarn) {} +RewriteObjCFragileABI(std::string inFile, std::unique_ptr OS, + DiagnosticsEngine , const LangOptions , + bool silenceMacroWarn) +: RewriteObjC(inFile, std::move(OS), D, LOpts, silenceMacroWarn) {} ~RewriteObjCFragileABI() override {} void Initialize(ASTContext ) 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 , const LangOptions , 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 , raw_ostream *OS, +clang::CreateObjCRewriter(const std::string , + std::unique_ptr OS, DiagnosticsEngine , const LangOptions , 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 ) { Index: cfe/trunk/lib/Frontend/Rewrite/RewriteModernObjC.cpp === --- cfe/trunk/lib/Frontend/Rewrite/RewriteModernObjC.cpp +++ cfe/trunk/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 , const LangOptions , -
Re: [PATCH] D21537: Frontend: Simplify ownership model for clang's output streams.
rsmith accepted this revision. rsmith added a comment. This revision is now accepted and ready to land. Yeah, I think this makes sense on balance, even though it does create a weird situation for the `ASTPrinter` case, where we don't really want to transfer ownership of the stream. Comment at: lib/CodeGen/CodeGenAction.cpp:705 @@ -703,3 +704,3 @@ case Backend_EmitNothing: -return nullptr; +return {}; case Backend_EmitMCNull: I think `return nullptr;` would be clearer here. Comment at: lib/Frontend/CompilerInstance.cpp:599 @@ -606,3 +598,3 @@ << EC.message(); -return nullptr; +return {}; } Likewise. https://reviews.llvm.org/D21537 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D21537: Frontend: Simplify ownership model for clang's output streams.
pcc added a comment. Ping. https://reviews.llvm.org/D21537 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D21537: Frontend: Simplify ownership model for clang's output streams.
pcc updated this revision to Diff 61317. pcc added a comment. - Move EmitAssemblyHelper's pass managers into CreatePasses http://reviews.llvm.org/D21537 Files: include/clang/CodeGen/BackendUtil.h include/clang/CodeGen/ObjectFilePCHContainerOperations.h include/clang/Frontend/ASTConsumers.h include/clang/Frontend/CompilerInstance.h include/clang/Frontend/FrontendActions.h include/clang/Frontend/PCHContainerOperations.h include/clang/Rewrite/Frontend/ASTConsumers.h lib/CodeGen/BackendUtil.cpp lib/CodeGen/CodeGenAction.cpp lib/CodeGen/ObjectFilePCHContainerOperations.cpp lib/Frontend/ASTConsumers.cpp lib/Frontend/ASTUnit.cpp lib/Frontend/CompilerInstance.cpp lib/Frontend/FrontendActions.cpp lib/Frontend/PCHContainerOperations.cpp lib/Frontend/Rewrite/FrontendActions.cpp lib/Frontend/Rewrite/HTMLPrint.cpp lib/Frontend/Rewrite/RewriteModernObjC.cpp lib/Frontend/Rewrite/RewriteObjC.cpp tools/clang-check/ClangCheck.cpp 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(::outs(), ASTDumpFilter); + return clang::CreateASTPrinter(nullptr, ASTDumpFilter); return llvm::make_unique(); } }; 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 , const LangOptions , bool silenceMacroWarn); @@ -506,11 +506,10 @@ class RewriteObjCFragileABI : public RewriteObjC { public: -RewriteObjCFragileABI(std::string inFile, raw_ostream *OS, -DiagnosticsEngine , const LangOptions , -bool silenceMacroWarn) : RewriteObjC(inFile, OS, - D, LOpts, - silenceMacroWarn) {} +RewriteObjCFragileABI(std::string inFile, std::unique_ptr OS, + DiagnosticsEngine , const LangOptions , + bool silenceMacroWarn) +: RewriteObjC(inFile, std::move(OS), D, LOpts, silenceMacroWarn) {} ~RewriteObjCFragileABI() override {} void Initialize(ASTContext ) 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 , const LangOptions , 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 , raw_ostream *OS, +clang::CreateObjCRewriter(const std::string , + std::unique_ptr OS, DiagnosticsEngine , const LangOptions , 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 ) { 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); -
[PATCH] D21537: Frontend: Simplify ownership model for clang's output streams.
pcc created this revision. pcc added a reviewer: rsmith. pcc added a subscriber: cfe-commits. This changes the CompilerInstance::createOutputFile function to return a std::unique_ptr, rather than an llvm::raw_ostream implicitly owned by the CompilerInstance. This in most cases required that I move ownership of the output stream to the relevant ASTConsumer. The motivation for this change is to allow BackendConsumer to be a client of interfaces such as D20268 which take ownership of the output stream. http://reviews.llvm.org/D21537 Files: include/clang/CodeGen/BackendUtil.h include/clang/CodeGen/ObjectFilePCHContainerOperations.h include/clang/Frontend/ASTConsumers.h include/clang/Frontend/CompilerInstance.h include/clang/Frontend/FrontendActions.h include/clang/Frontend/PCHContainerOperations.h include/clang/Rewrite/Frontend/ASTConsumers.h lib/CodeGen/BackendUtil.cpp lib/CodeGen/CodeGenAction.cpp lib/CodeGen/ObjectFilePCHContainerOperations.cpp lib/Frontend/ASTConsumers.cpp lib/Frontend/ASTUnit.cpp lib/Frontend/CompilerInstance.cpp lib/Frontend/FrontendActions.cpp lib/Frontend/PCHContainerOperations.cpp lib/Frontend/Rewrite/FrontendActions.cpp lib/Frontend/Rewrite/HTMLPrint.cpp lib/Frontend/Rewrite/RewriteModernObjC.cpp lib/Frontend/Rewrite/RewriteObjC.cpp tools/clang-check/ClangCheck.cpp 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(::outs(), ASTDumpFilter); + return clang::CreateASTPrinter(nullptr, ASTDumpFilter); return llvm::make_unique(); } }; 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 , const LangOptions , bool silenceMacroWarn); @@ -506,11 +506,10 @@ class RewriteObjCFragileABI : public RewriteObjC { public: -RewriteObjCFragileABI(std::string inFile, raw_ostream *OS, -DiagnosticsEngine , const LangOptions , -bool silenceMacroWarn) : RewriteObjC(inFile, OS, - D, LOpts, - silenceMacroWarn) {} +RewriteObjCFragileABI(std::string inFile, std::unique_ptr OS, + DiagnosticsEngine , const LangOptions , + bool silenceMacroWarn) +: RewriteObjC(inFile, std::move(OS), D, LOpts, silenceMacroWarn) {} ~RewriteObjCFragileABI() override {} void Initialize(ASTContext ) 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 , const LangOptions , 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 , raw_ostream *OS, +clang::CreateObjCRewriter(const std::string , + std::unique_ptr OS, DiagnosticsEngine , const LangOptions , 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 ) { Index: lib/Frontend/Rewrite/RewriteModernObjC.cpp === --- lib/Frontend/Rewrite/RewriteModernObjC.cpp +++