diff options
Diffstat (limited to 'clang-tools-extra/clangd/QueryDriverDatabase.cpp')
-rw-r--r-- | clang-tools-extra/clangd/QueryDriverDatabase.cpp | 24 |
1 files changed, 11 insertions, 13 deletions
diff --git a/clang-tools-extra/clangd/QueryDriverDatabase.cpp b/clang-tools-extra/clangd/QueryDriverDatabase.cpp index 6d51ec27ab3..c68596dff10 100644 --- a/clang-tools-extra/clangd/QueryDriverDatabase.cpp +++ b/clang-tools-extra/clangd/QueryDriverDatabase.cpp @@ -102,20 +102,19 @@ std::vector<std::string> extractSystemIncludes(PathRef Driver, return {}; } - llvm::SmallString<128> OutputPath; - auto EC = llvm::sys::fs::createTemporaryFile("system-includes", "clangd", - OutputPath); - if (EC) { + llvm::SmallString<128> StdErrPath; + if (auto EC = llvm::sys::fs::createTemporaryFile("system-includes", "clangd", + StdErrPath)) { elog("System include extraction: failed to create temporary file with " "error {0}", EC.message()); return {}; } auto CleanUp = llvm::make_scope_exit( - [&OutputPath]() { llvm::sys::fs::remove(OutputPath); }); + [&StdErrPath]() { llvm::sys::fs::remove(StdErrPath); }); llvm::Optional<llvm::StringRef> Redirects[] = { - {""}, llvm::StringRef(OutputPath), {""}}; + {""}, {""}, llvm::StringRef(StdErrPath)}; auto Type = driver::types::lookupTypeForExtension(Ext); if (Type == driver::types::TY_INVALID) { @@ -123,22 +122,21 @@ std::vector<std::string> extractSystemIncludes(PathRef Driver, return {}; } // Should we also preserve flags like "-sysroot", "-nostdinc" ? - const llvm::StringRef Args[] = {"-E", "-x", driver::types::getTypeName(Type), - "-", "-v"}; + const llvm::StringRef Args[] = { + Driver, "-E", "-x", driver::types::getTypeName(Type), "-", "-v"}; - int RC = - llvm::sys::ExecuteAndWait(Driver, Args, /*Env=*/llvm::None, Redirects); - if (RC) { + if (int RC = llvm::sys::ExecuteAndWait(Driver, Args, /*Env=*/llvm::None, + Redirects)) { elog("System include extraction: driver execution failed with return code: " "{0}", llvm::to_string(RC)); return {}; } - auto BufOrError = llvm::MemoryBuffer::getFile(OutputPath); + auto BufOrError = llvm::MemoryBuffer::getFile(StdErrPath); if (!BufOrError) { elog("System include extraction: failed to read {0} with error {1}", - OutputPath, BufOrError.getError().message()); + StdErrPath, BufOrError.getError().message()); return {}; } |