[PATCH] D148439: [clang-rename] Exit gracefully when no input provided

Shivam Gupta via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Apr 19 00:04:53 PDT 2023


xgupta updated this revision to Diff 514842.
xgupta marked an inline comment as done.
xgupta added a comment.

address comments


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D148439/new/

https://reviews.llvm.org/D148439

Files:
  clang/test/clang-rename/NonExistFile.cpp
  clang/tools/clang-rename/ClangRename.cpp


Index: clang/tools/clang-rename/ClangRename.cpp
===================================================================
--- clang/tools/clang-rename/ClangRename.cpp
+++ clang/tools/clang-rename/ClangRename.cpp
@@ -229,6 +229,10 @@
     Tool.applyAllReplacements(Rewrite);
     for (const auto &File : Files) {
       auto Entry = FileMgr.getFile(File);
+      if (!Entry) {
+        errs() << "clang-rename: " << File << " does not exist.\n";
+        return 1;
+      }
       const auto ID = Sources.getOrCreateFileID(*Entry, SrcMgr::C_User);
       Rewrite.getEditBuffer(ID).write(outs());
     }
Index: clang/test/clang-rename/NonExistFile.cpp
===================================================================
--- /dev/null
+++ clang/test/clang-rename/NonExistFile.cpp
@@ -0,0 +1,2 @@
+// RUN: not clang-rename -offset=0 -new-name=bar non-existing-file 2>&1 | FileCheck %s
+// CHECK: clang-rename: non-existing-file does not exist.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D148439.514842.patch
Type: text/x-patch
Size: 934 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230419/301f7f0d/attachment.bin>


More information about the cfe-commits mailing list