forked from OSchip/llvm-project
Fix for combined loop and nullptr convert tests
The rewriter was previously reading the content buffer from the file itself. Since we are now keeping the content in memory and writing to the file only once, the rewriter's buffer (from the file) was not in sync with the RefactoringTool's buffer. Adding an overrideFileContents call (similar to how Clang-format handles for this) will resolve this issue. Author: Jack Yang <jack.yang@intel.com> Reviewers: gribozavr, klimek llvm-svn: 174643
This commit is contained in:
parent
0749262a11
commit
37fea69391
|
@ -69,7 +69,7 @@ int LoopConvertTransform::apply(const FileContentsByPath &InputStates,
|
|||
return result;
|
||||
}
|
||||
|
||||
RewriterContainer Rewrite(LoopTool.getFiles());
|
||||
RewriterContainer Rewrite(LoopTool.getFiles(), InputStates);
|
||||
|
||||
// FIXME: Do something if some replacements didn't get applied?
|
||||
LoopTool.applyAllReplacements(Rewrite.getRewriter());
|
||||
|
|
|
@ -71,14 +71,24 @@ void collectResults(clang::Rewriter &Rewrite, FileContentsByPath &Results);
|
|||
/// of being recreated for every Transform subclass, especially diagnostics.
|
||||
class RewriterContainer {
|
||||
public:
|
||||
RewriterContainer(clang::FileManager &Files)
|
||||
RewriterContainer(clang::FileManager &Files,
|
||||
const FileContentsByPath &InputStates)
|
||||
: DiagOpts(new clang::DiagnosticOptions()),
|
||||
DiagnosticPrinter(llvm::errs(), DiagOpts.getPtr()),
|
||||
Diagnostics(llvm::IntrusiveRefCntPtr<clang::DiagnosticIDs>(
|
||||
new clang::DiagnosticIDs()),
|
||||
DiagOpts.getPtr(), &DiagnosticPrinter, false),
|
||||
Sources(Diagnostics, Files),
|
||||
Rewrite(Sources, DefaultLangOptions) {}
|
||||
Rewrite(Sources, DefaultLangOptions) {
|
||||
|
||||
// Overwrite source manager's file contents with data from InputStates
|
||||
for (FileContentsByPath::const_iterator I = InputStates.begin(),
|
||||
E = InputStates.end();
|
||||
I != E; ++I) {
|
||||
Sources.overrideFileContents(Files.getFile(I->first),
|
||||
llvm::MemoryBuffer::getMemBuffer(I->second));
|
||||
}
|
||||
}
|
||||
|
||||
clang::Rewriter &getRewriter() { return Rewrite; }
|
||||
|
||||
|
|
|
@ -53,7 +53,7 @@ int UseNullptrTransform::apply(const FileContentsByPath &InputStates,
|
|||
return result;
|
||||
}
|
||||
|
||||
RewriterContainer Rewrite(UseNullptrTool.getFiles());
|
||||
RewriterContainer Rewrite(UseNullptrTool.getFiles(), InputStates);
|
||||
|
||||
// FIXME: Do something if some replacements didn't get applied?
|
||||
UseNullptrTool.applyAllReplacements(Rewrite.getRewriter());
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
// RUN: FileCheck -input-file=%t.cpp %s
|
||||
// RUN: cpp11-migrate -loop-convert -use-nullptr -risk=risky %t_risky.cpp --
|
||||
// RUN: FileCheck -check-prefix=RISKY -input-file=%t_risky.cpp %s
|
||||
// XFAIL: *
|
||||
|
||||
#define NULL 0
|
||||
|
||||
|
|
Loading…
Reference in New Issue