Skip to content
Snippets Groups Projects
Commit 41372268 authored by Reid Kleckner's avatar Reid Kleckner
Browse files

[fixit] Use overwriteChangedFiles() to deal with Windows mapped files

Fixes one instance of PR17960.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@239920 91177308-0d34-0410-b5e6-96231b3b80d8
parent f8d44597
No related branches found
No related tags found
No related merge requests found
......@@ -27,7 +27,7 @@ class FileEntry;
class FixItOptions {
public:
FixItOptions() : FixWhatYouCan(false),
FixItOptions() : InPlace(false), FixWhatYouCan(false),
FixOnlyWarnings(false), Silent(false) { }
virtual ~FixItOptions();
......@@ -41,6 +41,10 @@ public:
///
virtual std::string RewriteFilename(const std::string &Filename, int &fd) = 0;
/// True if files should be updated in place. RewriteFilename is only called
/// if this is false.
bool InPlace;
/// \brief Whether to abort fixing a file when not all errors could be fixed.
bool FixWhatYouCan;
......
......@@ -81,6 +81,13 @@ bool FixItRewriter::WriteFixedFiles(
RewritesReceiver Rec(Rewrite);
Editor.applyRewrites(Rec);
if (FixItOpts->InPlace) {
// Overwriting open files on Windows is tricky, but the rewriter can do it
// for us.
Rewrite.overwriteChangedFiles();
return false;
}
for (iterator I = buffer_begin(), E = buffer_end(); I != E; ++I) {
const FileEntry *Entry = Rewrite.getSourceMgr().getFileEntryForID(I->first);
int fd;
......
......@@ -48,9 +48,10 @@ FixItAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) {
namespace {
class FixItRewriteInPlace : public FixItOptions {
public:
FixItRewriteInPlace() { InPlace = true; }
std::string RewriteFilename(const std::string &Filename, int &fd) override {
fd = -1;
return Filename;
llvm_unreachable("don't call RewriteFilename for inplace rewrites");
}
};
......
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment