[clangd] Explicitly fail if the file passed to --check is not valid.
authorHaojian Wu <hokein.wu@gmail.com>
Thu, 17 Jun 2021 12:33:24 +0000 (14:33 +0200)
committerHaojian Wu <hokein.wu@gmail.com>
Thu, 17 Jun 2021 14:41:06 +0000 (16:41 +0200)
Differential Revision: https://reviews.llvm.org/D104455

clang-tools-extra/clangd/tool/ClangdMain.cpp

index 0f9e5c8..6d70a9c 100644 (file)
@@ -909,7 +909,11 @@ clangd accepts flags on the commandline, and in the CLANGD_FLAGS environment var
 
   if (CheckFile.getNumOccurrences()) {
     llvm::SmallString<256> Path;
-    llvm::sys::fs::real_path(CheckFile, Path, /*expand_tilde=*/true);
+    if (auto Error =
+            llvm::sys::fs::real_path(CheckFile, Path, /*expand_tilde=*/true)) {
+      elog("Failed to resolve path {0}: {1}", CheckFile, Error.message());
+      return 1;
+    }
     log("Entering check mode (no LSP server)");
     uint32_t Begin = 0, End = std::numeric_limits<uint32_t>::max();
     if (!CheckFileLines.empty()) {