diff --git a/clang/docs/HowToSetupToolingForLLVM.rst b/clang/docs/HowToSetupToolingForLLVM.rst index 3812fc9f46e7..686aca840ada 100644 --- a/clang/docs/HowToSetupToolingForLLVM.rst +++ b/clang/docs/HowToSetupToolingForLLVM.rst @@ -133,7 +133,8 @@ Examples: if (this->ASTList.operator _Bool()) return clang::CreateASTDeclNodeLister(); if (this->ASTDump.operator _Bool()) - return clang::CreateASTDumper(this->ASTDumpFilter); + return clang::CreateASTDumper(nullptr /*Dump to stdout.*/, + this->ASTDumpFilter); if (this->ASTPrint.operator _Bool()) return clang::CreateASTPrinter(&llvm::outs(), this->ASTDumpFilter); return new clang::ASTConsumer(); diff --git a/clang/include/clang/Frontend/ASTConsumers.h b/clang/include/clang/Frontend/ASTConsumers.h index 53975a07ea94..2a13527df135 100644 --- a/clang/include/clang/Frontend/ASTConsumers.h +++ b/clang/include/clang/Frontend/ASTConsumers.h @@ -34,9 +34,10 @@ class TargetOptions; std::unique_ptr CreateASTPrinter(std::unique_ptr OS, StringRef FilterString); -// AST dumper: dumps the raw AST in human-readable form to stderr; this is -// intended for debugging. -std::unique_ptr CreateASTDumper(StringRef FilterString, +// AST dumper: dumps the raw AST in human-readable form to the given output +// stream, or stdout if OS is nullptr. +std::unique_ptr CreateASTDumper(std::unique_ptr OS, + StringRef FilterString, bool DumpDecls, bool Deserialize, bool DumpLookups); diff --git a/clang/lib/Frontend/ASTConsumers.cpp b/clang/lib/Frontend/ASTConsumers.cpp index 7dc475e26f76..a51d5b4a151c 100644 --- a/clang/lib/Frontend/ASTConsumers.cpp +++ b/clang/lib/Frontend/ASTConsumers.cpp @@ -138,12 +138,14 @@ clang::CreateASTPrinter(std::unique_ptr Out, FilterString); } -std::unique_ptr clang::CreateASTDumper(StringRef FilterString, - bool DumpDecls, - bool Deserialize, - bool DumpLookups) { +std::unique_ptr +clang::CreateASTDumper(std::unique_ptr Out, + StringRef FilterString, + bool DumpDecls, + bool Deserialize, + bool DumpLookups) { assert((DumpDecls || Deserialize || DumpLookups) && "nothing to dump"); - return llvm::make_unique(nullptr, + return llvm::make_unique(std::move(Out), Deserialize ? ASTPrinter::DumpFull : DumpDecls ? ASTPrinter::Dump : ASTPrinter::None, diff --git a/clang/lib/Frontend/FrontendActions.cpp b/clang/lib/Frontend/FrontendActions.cpp index 1eff566f0f40..8cb6a04224da 100644 --- a/clang/lib/Frontend/FrontendActions.cpp +++ b/clang/lib/Frontend/FrontendActions.cpp @@ -74,7 +74,8 @@ ASTPrintAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) { std::unique_ptr ASTDumpAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) { - return CreateASTDumper(CI.getFrontendOpts().ASTDumpFilter, + return CreateASTDumper(nullptr /*Dump to stdout.*/, + CI.getFrontendOpts().ASTDumpFilter, CI.getFrontendOpts().ASTDumpDecls, CI.getFrontendOpts().ASTDumpAll, CI.getFrontendOpts().ASTDumpLookups); diff --git a/clang/tools/clang-check/ClangCheck.cpp b/clang/tools/clang-check/ClangCheck.cpp index e190c0721afb..c970ac5adc77 100644 --- a/clang/tools/clang-check/ClangCheck.cpp +++ b/clang/tools/clang-check/ClangCheck.cpp @@ -138,7 +138,9 @@ public: if (ASTList) return clang::CreateASTDeclNodeLister(); if (ASTDump) - return clang::CreateASTDumper(ASTDumpFilter, /*DumpDecls=*/true, + return clang::CreateASTDumper(nullptr /*Dump to stdout.*/, + ASTDumpFilter, + /*DumpDecls=*/true, /*Deserialize=*/false, /*DumpLookups=*/false); if (ASTPrint) diff --git a/clang/tools/clang-import-test/clang-import-test.cpp b/clang/tools/clang-import-test/clang-import-test.cpp index d218d4107ede..106f3d1d150d 100644 --- a/clang/tools/clang-import-test/clang-import-test.cpp +++ b/clang/tools/clang-import-test/clang-import-test.cpp @@ -313,7 +313,8 @@ llvm::Expected Parse(const std::string &Path, auto &CG = *static_cast(ASTConsumers.back().get()); if (ShouldDumpAST) - ASTConsumers.push_back(CreateASTDumper("", true, false, false)); + ASTConsumers.push_back(CreateASTDumper(nullptr /*Dump to stdout.*/, + "", true, false, false)); CI.getDiagnosticClient().BeginSourceFile( CI.getCompilerInstance().getLangOpts(),