[clang-tools-extra] r281826 - [clang-rename] Fix handling of unchanged files
Alexander Shaposhnikov via cfe-commits
cfe-commits at lists.llvm.org
Sat Sep 17 10:08:47 PDT 2016
Author: alexshap
Date: Sat Sep 17 12:08:47 2016
New Revision: 281826
URL: http://llvm.org/viewvc/llvm-project?rev=281826&view=rev
Log:
[clang-rename] Fix handling of unchanged files
Fix the output of clang-rename for the files without modifications.
Update the code in clang-reorder-fields/tool/ClangReorderFields.cpp
to avoid inconsistency.
Example:
a.h:
struct A {};
a.cpp:
#include "a.h"
int main() { return 0; }
Before the changes the output looks like this:
clang-rename -qualified-name=A -new-name=B a.cpp
<<<<<INVALID SOURCE LOCATION>>>>>
Test plan: make -j8 check-clang-tools
Differential revision: https://reviews.llvm.org/D24634
Added:
clang-tools-extra/trunk/test/clang-rename/IncludeHeaderWithSymbol.cpp
clang-tools-extra/trunk/test/clang-rename/Inputs/HeaderWithSymbol.h
Modified:
clang-tools-extra/trunk/clang-rename/tool/ClangRename.cpp
clang-tools-extra/trunk/clang-reorder-fields/tool/ClangReorderFields.cpp
Modified: clang-tools-extra/trunk/clang-rename/tool/ClangRename.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-rename/tool/ClangRename.cpp?rev=281826&r1=281825&r2=281826&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-rename/tool/ClangRename.cpp (original)
+++ clang-tools-extra/trunk/clang-rename/tool/ClangRename.cpp Sat Sep 17 12:08:47 2016
@@ -222,7 +222,7 @@ int main(int argc, const char **argv) {
Tool.applyAllReplacements(Rewrite);
for (const auto &File : Files) {
const auto *Entry = FileMgr.getFile(File);
- auto ID = Sources.translateFile(Entry);
+ const auto ID = Sources.getOrCreateFileID(Entry, SrcMgr::C_User);
Rewrite.getEditBuffer(ID).write(outs());
}
}
Modified: clang-tools-extra/trunk/clang-reorder-fields/tool/ClangReorderFields.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-reorder-fields/tool/ClangReorderFields.cpp?rev=281826&r1=281825&r2=281826&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-reorder-fields/tool/ClangReorderFields.cpp (original)
+++ clang-tools-extra/trunk/clang-reorder-fields/tool/ClangReorderFields.cpp Sat Sep 17 12:08:47 2016
@@ -80,13 +80,8 @@ int main(int argc, const char **argv) {
for (const auto &File : Files) {
const auto *Entry = FileMgr.getFile(File);
- const auto ID = Sources.translateFile(Entry);
- // The method Rewriter::getRewriteBufferFor returns nullptr if
- // the file has not been changed.
- if (const auto *RB = Rewrite.getRewriteBufferFor(ID))
- RB->write(outs());
- else
- outs() << Sources.getMemoryBufferForFile(Entry)->getBuffer();
+ const auto ID = Sources.getOrCreateFileID(Entry, SrcMgr::C_User);
+ Rewrite.getEditBuffer(ID).write(outs());
}
return ExitCode;
Added: clang-tools-extra/trunk/test/clang-rename/IncludeHeaderWithSymbol.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-rename/IncludeHeaderWithSymbol.cpp?rev=281826&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-rename/IncludeHeaderWithSymbol.cpp (added)
+++ clang-tools-extra/trunk/test/clang-rename/IncludeHeaderWithSymbol.cpp Sat Sep 17 12:08:47 2016
@@ -0,0 +1,10 @@
+#include "Inputs/HeaderWithSymbol.h"
+
+int main() {
+ return 0; // CHECK: {{^ return 0;}}
+}
+
+// Test 1.
+// The file IncludeHeaderWithSymbol.cpp doesn't contain the symbol Foo
+// and is expected to be written to stdout without modifications
+// RUN: clang-rename -qualified-name=Foo -new-name=Bar %s -- | FileCheck %s
Added: clang-tools-extra/trunk/test/clang-rename/Inputs/HeaderWithSymbol.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-rename/Inputs/HeaderWithSymbol.h?rev=281826&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-rename/Inputs/HeaderWithSymbol.h (added)
+++ clang-tools-extra/trunk/test/clang-rename/Inputs/HeaderWithSymbol.h Sat Sep 17 12:08:47 2016
@@ -0,0 +1 @@
+struct Foo {};
More information about the cfe-commits
mailing list