This revision was not accepted when it landed; it landed in state "Needs Review". This revision was automatically updated to reflect the committed changes. Closed by commit rG62eec1584d2c: [clang-rename] Exit gracefully when no input provided (authored by xgupta).
Changed prior to commit: https://reviews.llvm.org/D148439?vs=514842&id=517178#toc Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D148439/new/ https://reviews.llvm.org/D148439 Files: clang/docs/ReleaseNotes.rst 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. Index: clang/docs/ReleaseNotes.rst =================================================================== --- clang/docs/ReleaseNotes.rst +++ clang/docs/ReleaseNotes.rst @@ -235,6 +235,8 @@ Bug Fixes in This Version ------------------------- +- Fix segfault while running clang-rename on a non existing file. + (`#36471 <https://github.com/llvm/llvm-project/issues/36471>`_) - Fix crash when diagnosing incorrect usage of ``_Nullable`` involving alias templates. (`#60344 <https://github.com/llvm/llvm-project/issues/60344>`_)
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. Index: clang/docs/ReleaseNotes.rst =================================================================== --- clang/docs/ReleaseNotes.rst +++ clang/docs/ReleaseNotes.rst @@ -235,6 +235,8 @@ Bug Fixes in This Version ------------------------- +- Fix segfault while running clang-rename on a non existing file. + (`#36471 <https://github.com/llvm/llvm-project/issues/36471>`_) - Fix crash when diagnosing incorrect usage of ``_Nullable`` involving alias templates. (`#60344 <https://github.com/llvm/llvm-project/issues/60344>`_)
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits