[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

llvm-svn: 281826
This commit is contained in:
Alexander Shaposhnikov 2016-09-17 17:08:47 +00:00
parent da5df7c99e
commit e4920c6fb9
4 changed files with 14 additions and 8 deletions

View File

@ -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());
}
}

View File

@ -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;

View File

@ -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

View File

@ -0,0 +1 @@
struct Foo {};