1 //===--- ARCMT.cpp - Migration to ARC mode --------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "Internals.h"
11 #include "clang/AST/ASTConsumer.h"
12 #include "clang/Basic/DiagnosticCategories.h"
13 #include "clang/Frontend/ASTUnit.h"
14 #include "clang/Frontend/CompilerInstance.h"
15 #include "clang/Frontend/FrontendAction.h"
16 #include "clang/Frontend/TextDiagnosticPrinter.h"
17 #include "clang/Frontend/Utils.h"
18 #include "clang/Lex/Preprocessor.h"
19 #include "clang/Rewrite/Core/Rewriter.h"
20 #include "clang/Sema/SemaDiagnostic.h"
21 #include "clang/Serialization/ASTReader.h"
22 #include "llvm/ADT/Triple.h"
23 #include "llvm/Support/MemoryBuffer.h"
24 using namespace clang;
25 using namespace arcmt;
27 bool CapturedDiagList::clearDiagnostic(ArrayRef<unsigned> IDs,
29 if (range.isInvalid())
33 ListTy::iterator I = List.begin();
34 while (I != List.end()) {
35 FullSourceLoc diagLoc = I->getLocation();
36 if ((IDs.empty() || // empty means clear all diagnostics in the range.
37 std::find(IDs.begin(), IDs.end(), I->getID()) != IDs.end()) &&
38 !diagLoc.isBeforeInTranslationUnitThan(range.getBegin()) &&
39 (diagLoc == range.getEnd() ||
40 diagLoc.isBeforeInTranslationUnitThan(range.getEnd()))) {
42 ListTy::iterator eraseS = I++;
43 if (eraseS->getLevel() != DiagnosticsEngine::Note)
44 while (I != List.end() && I->getLevel() == DiagnosticsEngine::Note)
46 // Clear the diagnostic and any notes following it.
47 I = List.erase(eraseS, I);
57 bool CapturedDiagList::hasDiagnostic(ArrayRef<unsigned> IDs,
58 SourceRange range) const {
59 if (range.isInvalid())
62 ListTy::const_iterator I = List.begin();
63 while (I != List.end()) {
64 FullSourceLoc diagLoc = I->getLocation();
65 if ((IDs.empty() || // empty means any diagnostic in the range.
66 std::find(IDs.begin(), IDs.end(), I->getID()) != IDs.end()) &&
67 !diagLoc.isBeforeInTranslationUnitThan(range.getBegin()) &&
68 (diagLoc == range.getEnd() ||
69 diagLoc.isBeforeInTranslationUnitThan(range.getEnd()))) {
79 void CapturedDiagList::reportDiagnostics(DiagnosticsEngine &Diags) const {
80 for (ListTy::const_iterator I = List.begin(), E = List.end(); I != E; ++I)
84 bool CapturedDiagList::hasErrors() const {
85 for (ListTy::const_iterator I = List.begin(), E = List.end(); I != E; ++I)
86 if (I->getLevel() >= DiagnosticsEngine::Error)
94 class CaptureDiagnosticConsumer : public DiagnosticConsumer {
95 DiagnosticsEngine &Diags;
96 DiagnosticConsumer &DiagClient;
97 CapturedDiagList &CapturedDiags;
98 bool HasBegunSourceFile;
100 CaptureDiagnosticConsumer(DiagnosticsEngine &diags,
101 DiagnosticConsumer &client,
102 CapturedDiagList &capturedDiags)
103 : Diags(diags), DiagClient(client), CapturedDiags(capturedDiags),
104 HasBegunSourceFile(false) { }
106 virtual void BeginSourceFile(const LangOptions &Opts,
107 const Preprocessor *PP) {
108 // Pass BeginSourceFile message onto DiagClient on first call.
109 // The corresponding EndSourceFile call will be made from an
110 // explicit call to FinishCapture.
111 if (!HasBegunSourceFile) {
112 DiagClient.BeginSourceFile(Opts, PP);
113 HasBegunSourceFile = true;
117 void FinishCapture() {
118 // Call EndSourceFile on DiagClient on completion of capture to
119 // enable VerifyDiagnosticConsumer to check diagnostics *after*
120 // it has received the diagnostic list.
121 if (HasBegunSourceFile) {
122 DiagClient.EndSourceFile();
123 HasBegunSourceFile = false;
127 virtual ~CaptureDiagnosticConsumer() {
128 assert(!HasBegunSourceFile && "FinishCapture not called!");
131 virtual void HandleDiagnostic(DiagnosticsEngine::Level level,
132 const Diagnostic &Info) {
133 if (DiagnosticIDs::isARCDiagnostic(Info.getID()) ||
134 level >= DiagnosticsEngine::Error || level == DiagnosticsEngine::Note) {
135 if (Info.getLocation().isValid())
136 CapturedDiags.push_back(StoredDiagnostic(level, Info));
140 // Non-ARC warnings are ignored.
141 Diags.setLastDiagnosticIgnored();
145 } // end anonymous namespace
147 static bool HasARCRuntime(CompilerInvocation &origCI) {
148 // This duplicates some functionality from Darwin::AddDeploymentTarget
149 // but this function is well defined, so keep it decoupled from the driver
150 // and avoid unrelated complications.
151 llvm::Triple triple(origCI.getTargetOpts().Triple);
153 if (triple.getOS() == llvm::Triple::IOS)
154 return triple.getOSMajorVersion() >= 5;
156 if (triple.getOS() == llvm::Triple::Darwin)
157 return triple.getOSMajorVersion() >= 11;
159 if (triple.getOS() == llvm::Triple::MacOSX) {
160 unsigned Major, Minor, Micro;
161 triple.getOSVersion(Major, Minor, Micro);
162 return Major > 10 || (Major == 10 && Minor >= 7);
168 static CompilerInvocation *
169 createInvocationForMigration(CompilerInvocation &origCI) {
170 OwningPtr<CompilerInvocation> CInvok;
171 CInvok.reset(new CompilerInvocation(origCI));
172 PreprocessorOptions &PPOpts = CInvok->getPreprocessorOpts();
173 if (!PPOpts.ImplicitPCHInclude.empty()) {
174 // We can't use a PCH because it was likely built in non-ARC mode and we
175 // want to parse in ARC. Include the original header.
176 FileManager FileMgr(origCI.getFileSystemOpts());
177 IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs());
178 IntrusiveRefCntPtr<DiagnosticsEngine> Diags(
179 new DiagnosticsEngine(DiagID, &origCI.getDiagnosticOpts(),
180 new IgnoringDiagConsumer()));
181 std::string OriginalFile =
182 ASTReader::getOriginalSourceFile(PPOpts.ImplicitPCHInclude,
184 if (!OriginalFile.empty())
185 PPOpts.Includes.insert(PPOpts.Includes.begin(), OriginalFile);
186 PPOpts.ImplicitPCHInclude.clear();
188 // FIXME: Get the original header of a PTH as well.
189 CInvok->getPreprocessorOpts().ImplicitPTHInclude.clear();
190 std::string define = getARCMTMacroName();
192 CInvok->getPreprocessorOpts().addMacroDef(define);
193 CInvok->getLangOpts()->ObjCAutoRefCount = true;
194 CInvok->getLangOpts()->setGC(LangOptions::NonGC);
195 CInvok->getDiagnosticOpts().ErrorLimit = 0;
196 CInvok->getDiagnosticOpts().PedanticErrors = 0;
198 // Ignore -Werror flags when migrating.
199 std::vector<std::string> WarnOpts;
200 for (std::vector<std::string>::iterator
201 I = CInvok->getDiagnosticOpts().Warnings.begin(),
202 E = CInvok->getDiagnosticOpts().Warnings.end(); I != E; ++I) {
203 if (!StringRef(*I).startswith("error"))
204 WarnOpts.push_back(*I);
206 WarnOpts.push_back("error=arc-unsafe-retained-assign");
207 CInvok->getDiagnosticOpts().Warnings = llvm_move(WarnOpts);
209 CInvok->getLangOpts()->ObjCARCWeak = HasARCRuntime(origCI);
211 return CInvok.take();
214 static void emitPremigrationErrors(const CapturedDiagList &arcDiags,
215 DiagnosticOptions *diagOpts,
217 TextDiagnosticPrinter printer(llvm::errs(), diagOpts);
218 IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs());
219 IntrusiveRefCntPtr<DiagnosticsEngine> Diags(
220 new DiagnosticsEngine(DiagID, diagOpts, &printer,
221 /*ShouldOwnClient=*/false));
222 Diags->setSourceManager(&PP.getSourceManager());
224 printer.BeginSourceFile(PP.getLangOpts(), &PP);
225 arcDiags.reportDiagnostics(*Diags);
226 printer.EndSourceFile();
229 //===----------------------------------------------------------------------===//
230 // checkForManualIssues.
231 //===----------------------------------------------------------------------===//
233 bool arcmt::checkForManualIssues(CompilerInvocation &origCI,
234 const FrontendInputFile &Input,
235 DiagnosticConsumer *DiagClient,
236 bool emitPremigrationARCErrors,
237 StringRef plistOut) {
238 if (!origCI.getLangOpts()->ObjC1)
241 LangOptions::GCMode OrigGCMode = origCI.getLangOpts()->getGC();
242 bool NoNSAllocReallocError = origCI.getMigratorOpts().NoNSAllocReallocError;
243 bool NoFinalizeRemoval = origCI.getMigratorOpts().NoFinalizeRemoval;
245 std::vector<TransformFn> transforms = arcmt::getAllTransformations(OrigGCMode,
247 assert(!transforms.empty());
249 OwningPtr<CompilerInvocation> CInvok;
250 CInvok.reset(createInvocationForMigration(origCI));
251 CInvok->getFrontendOpts().Inputs.clear();
252 CInvok->getFrontendOpts().Inputs.push_back(Input);
254 CapturedDiagList capturedDiags;
257 IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs());
258 IntrusiveRefCntPtr<DiagnosticsEngine> Diags(
259 new DiagnosticsEngine(DiagID, &origCI.getDiagnosticOpts(),
260 DiagClient, /*ShouldOwnClient=*/false));
262 // Filter of all diagnostics.
263 CaptureDiagnosticConsumer errRec(*Diags, *DiagClient, capturedDiags);
264 Diags->setClient(&errRec, /*ShouldOwnClient=*/false);
266 OwningPtr<ASTUnit> Unit(
267 ASTUnit::LoadFromCompilerInvocationAction(CInvok.take(), Diags));
269 errRec.FinishCapture();
273 // Don't filter diagnostics anymore.
274 Diags->setClient(DiagClient, /*ShouldOwnClient=*/false);
276 ASTContext &Ctx = Unit->getASTContext();
278 if (Diags->hasFatalErrorOccurred()) {
280 DiagClient->BeginSourceFile(Ctx.getLangOpts(), &Unit->getPreprocessor());
281 capturedDiags.reportDiagnostics(*Diags);
282 DiagClient->EndSourceFile();
283 errRec.FinishCapture();
287 if (emitPremigrationARCErrors)
288 emitPremigrationErrors(capturedDiags, &origCI.getDiagnosticOpts(),
289 Unit->getPreprocessor());
290 if (!plistOut.empty()) {
291 SmallVector<StoredDiagnostic, 8> arcDiags;
292 for (CapturedDiagList::iterator
293 I = capturedDiags.begin(), E = capturedDiags.end(); I != E; ++I)
294 arcDiags.push_back(*I);
295 writeARCDiagsToPlist(plistOut, arcDiags,
296 Ctx.getSourceManager(), Ctx.getLangOpts());
299 // After parsing of source files ended, we want to reuse the
300 // diagnostics objects to emit further diagnostics.
301 // We call BeginSourceFile because DiagnosticConsumer requires that
302 // diagnostics with source range information are emitted only in between
303 // BeginSourceFile() and EndSourceFile().
304 DiagClient->BeginSourceFile(Ctx.getLangOpts(), &Unit->getPreprocessor());
306 // No macros will be added since we are just checking and we won't modify
308 std::vector<SourceLocation> ARCMTMacroLocs;
310 TransformActions testAct(*Diags, capturedDiags, Ctx, Unit->getPreprocessor());
311 MigrationPass pass(Ctx, OrigGCMode, Unit->getSema(), testAct, capturedDiags,
313 pass.setNSAllocReallocError(NoNSAllocReallocError);
314 pass.setNoFinalizeRemoval(NoFinalizeRemoval);
316 for (unsigned i=0, e = transforms.size(); i != e; ++i)
319 capturedDiags.reportDiagnostics(*Diags);
321 DiagClient->EndSourceFile();
322 errRec.FinishCapture();
324 // If we are migrating code that gets the '-fobjc-arc' flag, make sure
325 // to remove it so that we don't get errors from normal compilation.
326 origCI.getLangOpts()->ObjCAutoRefCount = false;
328 return capturedDiags.hasErrors() || testAct.hasReportedErrors();
331 //===----------------------------------------------------------------------===//
332 // applyTransformations.
333 //===----------------------------------------------------------------------===//
335 static bool applyTransforms(CompilerInvocation &origCI,
336 const FrontendInputFile &Input,
337 DiagnosticConsumer *DiagClient,
339 bool emitPremigrationARCErrors,
340 StringRef plistOut) {
341 if (!origCI.getLangOpts()->ObjC1)
344 LangOptions::GCMode OrigGCMode = origCI.getLangOpts()->getGC();
346 // Make sure checking is successful first.
347 CompilerInvocation CInvokForCheck(origCI);
348 if (arcmt::checkForManualIssues(CInvokForCheck, Input, DiagClient,
349 emitPremigrationARCErrors, plistOut))
352 CompilerInvocation CInvok(origCI);
353 CInvok.getFrontendOpts().Inputs.clear();
354 CInvok.getFrontendOpts().Inputs.push_back(Input);
356 MigrationProcess migration(CInvok, DiagClient, outputDir);
357 bool NoFinalizeRemoval = origCI.getMigratorOpts().NoFinalizeRemoval;
359 std::vector<TransformFn> transforms = arcmt::getAllTransformations(OrigGCMode,
361 assert(!transforms.empty());
363 for (unsigned i=0, e = transforms.size(); i != e; ++i) {
364 bool err = migration.applyTransform(transforms[i]);
365 if (err) return true;
368 IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs());
369 IntrusiveRefCntPtr<DiagnosticsEngine> Diags(
370 new DiagnosticsEngine(DiagID, &origCI.getDiagnosticOpts(),
371 DiagClient, /*ShouldOwnClient=*/false));
373 if (outputDir.empty()) {
374 origCI.getLangOpts()->ObjCAutoRefCount = true;
375 return migration.getRemapper().overwriteOriginal(*Diags);
377 // If we are migrating code that gets the '-fobjc-arc' flag, make sure
378 // to remove it so that we don't get errors from normal compilation.
379 origCI.getLangOpts()->ObjCAutoRefCount = false;
380 return migration.getRemapper().flushToDisk(outputDir, *Diags);
384 bool arcmt::applyTransformations(CompilerInvocation &origCI,
385 const FrontendInputFile &Input,
386 DiagnosticConsumer *DiagClient) {
387 return applyTransforms(origCI, Input, DiagClient,
388 StringRef(), false, StringRef());
391 bool arcmt::migrateWithTemporaryFiles(CompilerInvocation &origCI,
392 const FrontendInputFile &Input,
393 DiagnosticConsumer *DiagClient,
395 bool emitPremigrationARCErrors,
396 StringRef plistOut) {
397 assert(!outputDir.empty() && "Expected output directory path");
398 return applyTransforms(origCI, Input, DiagClient,
399 outputDir, emitPremigrationARCErrors, plistOut);
402 bool arcmt::getFileRemappings(std::vector<std::pair<std::string,std::string> > &
405 DiagnosticConsumer *DiagClient) {
406 assert(!outputDir.empty());
408 IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs());
409 IntrusiveRefCntPtr<DiagnosticsEngine> Diags(
410 new DiagnosticsEngine(DiagID, new DiagnosticOptions,
411 DiagClient, /*ShouldOwnClient=*/false));
413 FileRemapper remapper;
414 bool err = remapper.initFromDisk(outputDir, *Diags,
415 /*ignoreIfFilesChanged=*/true);
419 PreprocessorOptions PPOpts;
420 remapper.applyMappings(PPOpts);
421 remap = PPOpts.RemappedFiles;
426 bool arcmt::getFileRemappingsFromFileList(
427 std::vector<std::pair<std::string,std::string> > &remap,
428 ArrayRef<StringRef> remapFiles,
429 DiagnosticConsumer *DiagClient) {
430 bool hasErrorOccurred = false;
431 llvm::StringMap<bool> Uniquer;
433 IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs());
434 IntrusiveRefCntPtr<DiagnosticsEngine> Diags(
435 new DiagnosticsEngine(DiagID, new DiagnosticOptions,
436 DiagClient, /*ShouldOwnClient=*/false));
438 for (ArrayRef<StringRef>::iterator
439 I = remapFiles.begin(), E = remapFiles.end(); I != E; ++I) {
442 FileRemapper remapper;
443 bool err = remapper.initFromFile(file, *Diags,
444 /*ignoreIfFilesChanged=*/true);
445 hasErrorOccurred = hasErrorOccurred || err;
449 PreprocessorOptions PPOpts;
450 remapper.applyMappings(PPOpts);
451 for (PreprocessorOptions::remapped_file_iterator
452 RI = PPOpts.remapped_file_begin(), RE = PPOpts.remapped_file_end();
454 bool &inserted = Uniquer[RI->first];
458 remap.push_back(*RI);
462 return hasErrorOccurred;
465 //===----------------------------------------------------------------------===//
466 // CollectTransformActions.
467 //===----------------------------------------------------------------------===//
471 class ARCMTMacroTrackerPPCallbacks : public PPCallbacks {
472 std::vector<SourceLocation> &ARCMTMacroLocs;
475 ARCMTMacroTrackerPPCallbacks(std::vector<SourceLocation> &ARCMTMacroLocs)
476 : ARCMTMacroLocs(ARCMTMacroLocs) { }
478 virtual void MacroExpands(const Token &MacroNameTok, const MacroDirective *MD,
479 SourceRange Range, const MacroArgs *Args) {
480 if (MacroNameTok.getIdentifierInfo()->getName() == getARCMTMacroName())
481 ARCMTMacroLocs.push_back(MacroNameTok.getLocation());
485 class ARCMTMacroTrackerAction : public ASTFrontendAction {
486 std::vector<SourceLocation> &ARCMTMacroLocs;
489 ARCMTMacroTrackerAction(std::vector<SourceLocation> &ARCMTMacroLocs)
490 : ARCMTMacroLocs(ARCMTMacroLocs) { }
492 virtual ASTConsumer *CreateASTConsumer(CompilerInstance &CI,
494 CI.getPreprocessor().addPPCallbacks(
495 new ARCMTMacroTrackerPPCallbacks(ARCMTMacroLocs));
496 return new ASTConsumer();
500 class RewritesApplicator : public TransformActions::RewriteReceiver {
502 MigrationProcess::RewriteListener *Listener;
505 RewritesApplicator(Rewriter &rewriter, ASTContext &ctx,
506 MigrationProcess::RewriteListener *listener)
507 : rewriter(rewriter), Listener(listener) {
509 Listener->start(ctx);
511 ~RewritesApplicator() {
516 virtual void insert(SourceLocation loc, StringRef text) {
517 bool err = rewriter.InsertText(loc, text, /*InsertAfter=*/true,
518 /*indentNewLines=*/true);
519 if (!err && Listener)
520 Listener->insert(loc, text);
523 virtual void remove(CharSourceRange range) {
524 Rewriter::RewriteOptions removeOpts;
525 removeOpts.IncludeInsertsAtBeginOfRange = false;
526 removeOpts.IncludeInsertsAtEndOfRange = false;
527 removeOpts.RemoveLineIfEmpty = true;
529 bool err = rewriter.RemoveText(range, removeOpts);
530 if (!err && Listener)
531 Listener->remove(range);
534 virtual void increaseIndentation(CharSourceRange range,
535 SourceLocation parentIndent) {
536 rewriter.IncreaseIndentation(range, parentIndent);
540 } // end anonymous namespace.
542 /// \brief Anchor for VTable.
543 MigrationProcess::RewriteListener::~RewriteListener() { }
545 MigrationProcess::MigrationProcess(const CompilerInvocation &CI,
546 DiagnosticConsumer *diagClient,
548 : OrigCI(CI), DiagClient(diagClient) {
549 if (!outputDir.empty()) {
550 IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs());
551 IntrusiveRefCntPtr<DiagnosticsEngine> Diags(
552 new DiagnosticsEngine(DiagID, &CI.getDiagnosticOpts(),
553 DiagClient, /*ShouldOwnClient=*/false));
554 Remapper.initFromDisk(outputDir, *Diags, /*ignoreIfFilesChanges=*/true);
558 bool MigrationProcess::applyTransform(TransformFn trans,
559 RewriteListener *listener) {
560 OwningPtr<CompilerInvocation> CInvok;
561 CInvok.reset(createInvocationForMigration(OrigCI));
562 CInvok->getDiagnosticOpts().IgnoreWarnings = true;
564 Remapper.applyMappings(CInvok->getPreprocessorOpts());
566 CapturedDiagList capturedDiags;
567 std::vector<SourceLocation> ARCMTMacroLocs;
570 IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs());
571 IntrusiveRefCntPtr<DiagnosticsEngine> Diags(
572 new DiagnosticsEngine(DiagID, new DiagnosticOptions,
573 DiagClient, /*ShouldOwnClient=*/false));
575 // Filter of all diagnostics.
576 CaptureDiagnosticConsumer errRec(*Diags, *DiagClient, capturedDiags);
577 Diags->setClient(&errRec, /*ShouldOwnClient=*/false);
579 OwningPtr<ARCMTMacroTrackerAction> ASTAction;
580 ASTAction.reset(new ARCMTMacroTrackerAction(ARCMTMacroLocs));
582 OwningPtr<ASTUnit> Unit(
583 ASTUnit::LoadFromCompilerInvocationAction(CInvok.take(), Diags,
586 errRec.FinishCapture();
589 Unit->setOwnsRemappedFileBuffers(false); // FileRemapper manages that.
591 // Don't filter diagnostics anymore.
592 Diags->setClient(DiagClient, /*ShouldOwnClient=*/false);
594 ASTContext &Ctx = Unit->getASTContext();
596 if (Diags->hasFatalErrorOccurred()) {
598 DiagClient->BeginSourceFile(Ctx.getLangOpts(), &Unit->getPreprocessor());
599 capturedDiags.reportDiagnostics(*Diags);
600 DiagClient->EndSourceFile();
601 errRec.FinishCapture();
605 // After parsing of source files ended, we want to reuse the
606 // diagnostics objects to emit further diagnostics.
607 // We call BeginSourceFile because DiagnosticConsumer requires that
608 // diagnostics with source range information are emitted only in between
609 // BeginSourceFile() and EndSourceFile().
610 DiagClient->BeginSourceFile(Ctx.getLangOpts(), &Unit->getPreprocessor());
612 Rewriter rewriter(Ctx.getSourceManager(), Ctx.getLangOpts());
613 TransformActions TA(*Diags, capturedDiags, Ctx, Unit->getPreprocessor());
614 MigrationPass pass(Ctx, OrigCI.getLangOpts()->getGC(),
615 Unit->getSema(), TA, capturedDiags, ARCMTMacroLocs);
620 RewritesApplicator applicator(rewriter, Ctx, listener);
621 TA.applyRewrites(applicator);
624 DiagClient->EndSourceFile();
625 errRec.FinishCapture();
627 if (DiagClient->getNumErrors())
630 for (Rewriter::buffer_iterator
631 I = rewriter.buffer_begin(), E = rewriter.buffer_end(); I != E; ++I) {
632 FileID FID = I->first;
633 RewriteBuffer &buf = I->second;
634 const FileEntry *file = Ctx.getSourceManager().getFileEntryForID(FID);
636 std::string newFname = file->getName();
637 newFname += "-trans";
638 SmallString<512> newText;
639 llvm::raw_svector_ostream vecOS(newText);
642 llvm::MemoryBuffer *memBuf = llvm::MemoryBuffer::getMemBufferCopy(
643 StringRef(newText.data(), newText.size()), newFname);
644 SmallString<64> filePath(file->getName());
645 Unit->getFileManager().FixupRelativePath(filePath);
646 Remapper.remap(filePath.str(), memBuf);