From cfca06d7963fa0909f90483b42a6d7d194d01e08 Mon Sep 17 00:00:00 2001 From: Dimitry Andric Date: Sun, 26 Jul 2020 19:36:28 +0000 Subject: Vendor import of llvm-project master 2e10b7a39b9, the last commit before the llvmorg-12-init tag, from which release/11.x was branched. --- clang/lib/Tooling/Tooling.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'clang/lib/Tooling/Tooling.cpp') diff --git a/clang/lib/Tooling/Tooling.cpp b/clang/lib/Tooling/Tooling.cpp index 4a0618c50e42..40b6cff0d627 100644 --- a/clang/lib/Tooling/Tooling.cpp +++ b/clang/lib/Tooling/Tooling.cpp @@ -141,11 +141,13 @@ namespace clang { namespace tooling { /// Returns a clang build invocation initialized from the CC1 flags. -CompilerInvocation *newInvocation( - DiagnosticsEngine *Diagnostics, const llvm::opt::ArgStringList &CC1Args) { +CompilerInvocation *newInvocation(DiagnosticsEngine *Diagnostics, + const llvm::opt::ArgStringList &CC1Args, + const char *const BinaryName) { assert(!CC1Args.empty() && "Must at least contain the program name!"); CompilerInvocation *Invocation = new CompilerInvocation; - CompilerInvocation::CreateFromArgs(*Invocation, CC1Args, *Diagnostics); + CompilerInvocation::CreateFromArgs(*Invocation, CC1Args, *Diagnostics, + BinaryName); Invocation->getFrontendOpts().DisableFree = false; Invocation->getCodeGenOpts().DisableFree = false; return Invocation; @@ -234,7 +236,7 @@ llvm::Expected getAbsolutePath(llvm::vfs::FileSystem &FS, if (auto EC = FS.makeAbsolute(AbsolutePath)) return llvm::errorCodeToError(EC); llvm::sys::path::native(AbsolutePath); - return AbsolutePath.str(); + return std::string(AbsolutePath.str()); } std::string getAbsolutePath(StringRef File) { @@ -345,7 +347,7 @@ bool ToolInvocation::run() { if (!CC1Args) return false; std::unique_ptr Invocation( - newInvocation(&Diagnostics, *CC1Args)); + newInvocation(&Diagnostics, *CC1Args, BinaryName)); // FIXME: remove this when all users have migrated! for (const auto &It : MappedFileContents) { // Inject the code as the given file name into the preprocessor options. @@ -619,7 +621,8 @@ buildASTFromCode(StringRef Code, StringRef FileName, std::unique_ptr buildASTFromCodeWithArgs( StringRef Code, const std::vector &Args, StringRef FileName, StringRef ToolName, std::shared_ptr PCHContainerOps, - ArgumentsAdjuster Adjuster, const FileContentMappings &VirtualMappedFiles) { + ArgumentsAdjuster Adjuster, const FileContentMappings &VirtualMappedFiles, + DiagnosticConsumer *DiagConsumer) { std::vector> ASTs; ASTBuilderAction Action(ASTs); llvm::IntrusiveRefCntPtr OverlayFileSystem( @@ -633,6 +636,7 @@ std::unique_ptr buildASTFromCodeWithArgs( ToolInvocation Invocation( getSyntaxOnlyToolArgs(ToolName, Adjuster(Args, FileName), FileName), &Action, Files.get(), std::move(PCHContainerOps)); + Invocation.setDiagnosticConsumer(DiagConsumer); InMemoryFileSystem->addFile(FileName, 0, llvm::MemoryBuffer::getMemBufferCopy(Code)); -- cgit v1.2.3