diff options
author | Fariborz Jahanian <fjahanian@apple.com> | 2012-01-25 00:20:29 +0000 |
---|---|---|
committer | Fariborz Jahanian <fjahanian@apple.com> | 2012-01-25 00:20:29 +0000 |
commit | aa7b9aa10dd90f79c37e0af7f4c6a0f9efeb288c (patch) | |
tree | e14b7c78706eeb22d22287ee913952085a911a53 /clang/lib | |
parent | c454afedff4c709449d76b5700cc33b503f1d5b7 (diff) | |
download | bcm5719-llvm-aa7b9aa10dd90f79c37e0af7f4c6a0f9efeb288c.tar.gz bcm5719-llvm-aa7b9aa10dd90f79c37e0af7f4c6a0f9efeb288c.zip |
arc migrator: Provide infrastructure to add options
specific to migrator. Use its first option to
warn migrating from GC to arc when
NSAllocateCollectable/NSReallocateCollectable is used.
// rdar://10532541
llvm-svn: 148887
Diffstat (limited to 'clang/lib')
-rw-r--r-- | clang/lib/ARCMigrate/ARCMT.cpp | 2 | ||||
-rw-r--r-- | clang/lib/ARCMigrate/Internals.h | 8 | ||||
-rw-r--r-- | clang/lib/ARCMigrate/TransGCCalls.cpp | 11 | ||||
-rw-r--r-- | clang/lib/ARCMigrate/TransformActions.cpp | 19 | ||||
-rw-r--r-- | clang/lib/Frontend/CompilerInvocation.cpp | 6 |
5 files changed, 42 insertions, 4 deletions
diff --git a/clang/lib/ARCMigrate/ARCMT.cpp b/clang/lib/ARCMigrate/ARCMT.cpp index 9a07245e2c1..09752f0d612 100644 --- a/clang/lib/ARCMigrate/ARCMT.cpp +++ b/clang/lib/ARCMigrate/ARCMT.cpp @@ -229,6 +229,7 @@ bool arcmt::checkForManualIssues(CompilerInvocation &origCI, return false; LangOptions::GCMode OrigGCMode = origCI.getLangOpts()->getGC(); + bool NoNSAllocReallocError = origCI.getMigratorOpts().NoNSAllocReallocError; std::vector<TransformFn> transforms = arcmt::getAllTransformations(OrigGCMode); assert(!transforms.empty()); @@ -292,6 +293,7 @@ bool arcmt::checkForManualIssues(CompilerInvocation &origCI, TransformActions testAct(*Diags, capturedDiags, Ctx, Unit->getPreprocessor()); MigrationPass pass(Ctx, OrigGCMode, Unit->getSema(), testAct, ARCMTMacroLocs); + pass.setNSAllocReallocError(NoNSAllocReallocError); for (unsigned i=0, e = transforms.size(); i != e; ++i) transforms[i](pass); diff --git a/clang/lib/ARCMigrate/Internals.h b/clang/lib/ARCMigrate/Internals.h index 06d9f8259fa..78bf341fe6b 100644 --- a/clang/lib/ARCMigrate/Internals.h +++ b/clang/lib/ARCMigrate/Internals.h @@ -94,6 +94,8 @@ public: void reportError(StringRef error, SourceLocation loc, SourceRange range = SourceRange()); + void reportWarning(StringRef warning, SourceLocation loc, + SourceRange range = SourceRange()); void reportNote(StringRef note, SourceLocation loc, SourceRange range = SourceRange()); @@ -138,6 +140,7 @@ class MigrationPass { public: ASTContext &Ctx; LangOptions::GCMode OrigGCMode; + MigratorOptions MigOptions; Sema &SemaRef; TransformActions &TA; std::vector<SourceLocation> &ARCMTMacroLocs; @@ -145,10 +148,13 @@ public: MigrationPass(ASTContext &Ctx, LangOptions::GCMode OrigGCMode, Sema &sema, TransformActions &TA, std::vector<SourceLocation> &ARCMTMacroLocs) - : Ctx(Ctx), OrigGCMode(OrigGCMode), SemaRef(sema), TA(TA), + : Ctx(Ctx), OrigGCMode(OrigGCMode), MigOptions(), + SemaRef(sema), TA(TA), ARCMTMacroLocs(ARCMTMacroLocs) { } bool isGCMigration() const { return OrigGCMode != LangOptions::NonGC; } + bool noNSAllocReallocError() const { return MigOptions.NoNSAllocReallocError; } + void setNSAllocReallocError(bool val) { MigOptions.NoNSAllocReallocError = val; } }; static inline StringRef getARCMTMacroName() { diff --git a/clang/lib/ARCMigrate/TransGCCalls.cpp b/clang/lib/ARCMigrate/TransGCCalls.cpp index 7c0819a677c..1be902088c6 100644 --- a/clang/lib/ARCMigrate/TransGCCalls.cpp +++ b/clang/lib/ARCMigrate/TransGCCalls.cpp @@ -38,9 +38,14 @@ public: TransformActions &TA = MigrateCtx.Pass.TA; if (MigrateCtx.isGCOwnedNonObjC(E->getType())) { - TA.reportError("call returns pointer to GC managed memory; " - "it will become unmanaged in ARC", - E->getLocStart(), E->getSourceRange()); + if (MigrateCtx.Pass.noNSAllocReallocError()) + TA.reportWarning("call returns pointer to GC managed memory; " + "it will become unmanaged in ARC", + E->getLocStart(), E->getSourceRange()); + else + TA.reportError("call returns pointer to GC managed memory; " + "it will become unmanaged in ARC", + E->getLocStart(), E->getSourceRange()); return true; } diff --git a/clang/lib/ARCMigrate/TransformActions.cpp b/clang/lib/ARCMigrate/TransformActions.cpp index 7ad9b6005dc..0ecfeb54f85 100644 --- a/clang/lib/ARCMigrate/TransformActions.cpp +++ b/clang/lib/ARCMigrate/TransformActions.cpp @@ -692,6 +692,25 @@ void TransformActions::reportError(StringRef error, SourceLocation loc, ReportedErrors = true; } +void TransformActions::reportWarning(StringRef warning, SourceLocation loc, + SourceRange range) { + assert(!static_cast<TransformActionsImpl*>(Impl)->isInTransaction() && + "Warning should be emitted out of a transaction"); + + SourceManager &SM = static_cast<TransformActionsImpl*>(Impl)-> + getASTContext().getSourceManager(); + if (SM.isInSystemHeader(SM.getExpansionLoc(loc))) + return; + + // FIXME: Use a custom category name to distinguish rewriter errors. + std::string rewriterWarn = "[rewriter] "; + rewriterWarn += warning; + unsigned diagID + = Diags.getDiagnosticIDs()->getCustomDiagID(DiagnosticIDs::Warning, + rewriterWarn); + Diags.Report(loc, diagID) << range; +} + void TransformActions::reportNote(StringRef note, SourceLocation loc, SourceRange range) { assert(!static_cast<TransformActionsImpl*>(Impl)->isInTransaction() && diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp index f4576093d8c..aa367b0a74a 100644 --- a/clang/lib/Frontend/CompilerInvocation.cpp +++ b/clang/lib/Frontend/CompilerInvocation.cpp @@ -1053,6 +1053,11 @@ static bool ParseAnalyzerArgs(AnalyzerOptions &Opts, ArgList &Args, return Success; } +static bool ParseMigratorArgs(MigratorOptions &Opts, ArgList &Args) { + Opts.NoNSAllocReallocError = Args.hasArg(OPT_migrator_no_nsalloc_error); + return true; +} + static bool ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args, InputKind IK, DiagnosticsEngine &Diags) { using namespace cc1options; @@ -2051,6 +2056,7 @@ bool CompilerInvocation::CreateFromArgs(CompilerInvocation &Res, } Success = ParseAnalyzerArgs(Res.getAnalyzerOpts(), *Args, Diags) && Success; + Success = ParseMigratorArgs(Res.getMigratorOpts(), *Args) && Success; ParseDependencyOutputArgs(Res.getDependencyOutputOpts(), *Args); Success = ParseDiagnosticArgs(Res.getDiagnosticOpts(), *Args, Diags) && Success; |