diff options
author | Ted Kremenek <kremenek@apple.com> | 2011-11-17 23:01:24 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2011-11-17 23:01:24 +0000 |
commit | d3b74d9ca4f239a7a90ad193378c494306c57352 (patch) | |
tree | 65d677835cc2b3e9625285be0f165d5b6e9e8a65 /lib/ARCMigrate | |
parent | d04a982d3472d98e58f58dfc327ca11e236980f5 (diff) |
Make 'LangOptions' in CompilerInvocation a heap-allocated, reference counted object. I discovered that llvm::RefCountedBase<T> has
a bug where the reference count is copied in the copy constructor, which means that there were cases when the CompilerInvocation
objects created by ASTUnit were actually leaked. When I fixed that bug locally, it showed that a whole bunch of code assumed
that the LangOptions object that was part of CompilerInvocation was still alive. By making it heap-allocated and reference counted,
we can keep it around after the CompilerInvocation object goes away.
As part of this change, change CompilerInvocation:getLangOptions() to return a pointer, acting as another clue that this
object may outlive the CompilerInvocation object.
This commit doesn't fix the CompilerInvocation leak itself. That will come when I commit the fix to llvm::RefCountedBase<T> to
mainline LLVM.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@144930 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/ARCMigrate')
-rw-r--r-- | lib/ARCMigrate/ARCMT.cpp | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/lib/ARCMigrate/ARCMT.cpp b/lib/ARCMigrate/ARCMT.cpp index f35f2577ed..06bc6b8c04 100644 --- a/lib/ARCMigrate/ARCMT.cpp +++ b/lib/ARCMigrate/ARCMT.cpp @@ -190,13 +190,14 @@ createInvocationForMigration(CompilerInvocation &origCI) { CInvok->getPreprocessorOpts().ImplicitPTHInclude = std::string(); std::string define = getARCMTMacroName(); define += '='; + CInvok->setLangOpts(new LangOptions(*CInvok->getLangOpts())); CInvok->getPreprocessorOpts().addMacroDef(define); - CInvok->getLangOpts().ObjCAutoRefCount = true; - CInvok->getLangOpts().setGC(LangOptions::NonGC); + CInvok->getLangOpts()->ObjCAutoRefCount = true; + CInvok->getLangOpts()->setGC(LangOptions::NonGC); CInvok->getDiagnosticOpts().ErrorLimit = 0; CInvok->getDiagnosticOpts().Warnings.push_back( "error=arc-unsafe-retained-assign"); - CInvok->getLangOpts().ObjCRuntimeHasWeak = HasARCRuntime(origCI); + CInvok->getLangOpts()->ObjCRuntimeHasWeak = HasARCRuntime(origCI); return CInvok.take(); } @@ -224,10 +225,10 @@ bool arcmt::checkForManualIssues(CompilerInvocation &origCI, DiagnosticConsumer *DiagClient, bool emitPremigrationARCErrors, StringRef plistOut) { - if (!origCI.getLangOpts().ObjC1) + if (!origCI.getLangOpts()->ObjC1) return false; - LangOptions::GCMode OrigGCMode = origCI.getLangOpts().getGC(); + LangOptions::GCMode OrigGCMode = origCI.getLangOpts()->getGC(); std::vector<TransformFn> transforms = arcmt::getAllTransformations(OrigGCMode); assert(!transforms.empty()); @@ -301,7 +302,7 @@ bool arcmt::checkForManualIssues(CompilerInvocation &origCI, // If we are migrating code that gets the '-fobjc-arc' flag, make sure // to remove it so that we don't get errors from normal compilation. - origCI.getLangOpts().ObjCAutoRefCount = false; + origCI.getLangOpts()->ObjCAutoRefCount = false; return capturedDiags.hasErrors() || testAct.hasReportedErrors(); } @@ -316,10 +317,10 @@ static bool applyTransforms(CompilerInvocation &origCI, StringRef outputDir, bool emitPremigrationARCErrors, StringRef plistOut) { - if (!origCI.getLangOpts().ObjC1) + if (!origCI.getLangOpts()->ObjC1) return false; - LangOptions::GCMode OrigGCMode = origCI.getLangOpts().getGC(); + LangOptions::GCMode OrigGCMode = origCI.getLangOpts()->getGC(); // Make sure checking is successful first. CompilerInvocation CInvokForCheck(origCI); @@ -346,12 +347,12 @@ static bool applyTransforms(CompilerInvocation &origCI, new DiagnosticsEngine(DiagID, DiagClient, /*ShouldOwnClient=*/false)); if (outputDir.empty()) { - origCI.getLangOpts().ObjCAutoRefCount = true; + origCI.getLangOpts()->ObjCAutoRefCount = true; return migration.getRemapper().overwriteOriginal(*Diags); } else { // If we are migrating code that gets the '-fobjc-arc' flag, make sure // to remove it so that we don't get errors from normal compilation. - origCI.getLangOpts().ObjCAutoRefCount = false; + origCI.getLangOpts()->ObjCAutoRefCount = false; return migration.getRemapper().flushToDisk(outputDir, *Diags); } } @@ -542,7 +543,7 @@ bool MigrationProcess::applyTransform(TransformFn trans, Rewriter rewriter(Ctx.getSourceManager(), Ctx.getLangOptions()); TransformActions TA(*Diags, capturedDiags, Ctx, Unit->getPreprocessor()); - MigrationPass pass(Ctx, OrigCI.getLangOpts().getGC(), + MigrationPass pass(Ctx, OrigCI.getLangOpts()->getGC(), Unit->getSema(), TA, ARCMTMacroLocs); trans(pass); |