[PATCH] Fix for combined loop and nullptr convert tests

Jack Yang jy7.yang at gmail.com
Tue Feb 5 14:21:21 PST 2013


Hi gribozavr,

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.

http://llvm-reviews.chandlerc.com/D371

Files:
  cpp11-migrate/LoopConvert/LoopConvert.cpp
  cpp11-migrate/Transform.h
  cpp11-migrate/UseNullptr/UseNullptr.cpp
  test/cpp11-migrate/Combined/combined.cpp

Index: cpp11-migrate/LoopConvert/LoopConvert.cpp
===================================================================
--- cpp11-migrate/LoopConvert/LoopConvert.cpp
+++ cpp11-migrate/LoopConvert/LoopConvert.cpp
@@ -69,7 +69,7 @@
     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());
Index: cpp11-migrate/Transform.h
===================================================================
--- cpp11-migrate/Transform.h
+++ cpp11-migrate/Transform.h
@@ -71,14 +71,26 @@
 /// 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; }
 
Index: cpp11-migrate/UseNullptr/UseNullptr.cpp
===================================================================
--- cpp11-migrate/UseNullptr/UseNullptr.cpp
+++ cpp11-migrate/UseNullptr/UseNullptr.cpp
@@ -53,7 +53,7 @@
     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());
Index: test/cpp11-migrate/Combined/combined.cpp
===================================================================
--- test/cpp11-migrate/Combined/combined.cpp
+++ test/cpp11-migrate/Combined/combined.cpp
@@ -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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D371.1.patch
Type: text/x-patch
Size: 2714 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130205/dcf64dce/attachment.bin>


More information about the cfe-commits mailing list