diff options
-rw-r--r-- | clang/include/clang/Driver/CC1Options.td | 6 | ||||
-rw-r--r-- | clang/include/clang/Frontend/CompilerInvocation.h | 8 | ||||
-rw-r--r-- | clang/include/clang/Frontend/MigratorOptions.h | 29 | ||||
-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 | ||||
-rw-r--r-- | clang/test/ARCMT/GC-check-warn-nsalloc.m | 12 |
9 files changed, 97 insertions, 4 deletions
diff --git a/clang/include/clang/Driver/CC1Options.td b/clang/include/clang/Driver/CC1Options.td index 3d599061b06..86457d9e784 100644 --- a/clang/include/clang/Driver/CC1Options.td +++ b/clang/include/clang/Driver/CC1Options.td @@ -101,6 +101,12 @@ def analyzer_checker_help : Flag<"-analyzer-checker-help">, HelpText<"Display the list of analyzer checkers that are available">; //===----------------------------------------------------------------------===// +// Migrator Options +//===----------------------------------------------------------------------===// +def migrator_no_nsalloc_error : Flag<"-no-ns-alloc-error">, + HelpText<"Do not error on use of NSAllocateCollectable/NSReallocateCollectable">; + +//===----------------------------------------------------------------------===// // CodeGen Options //===----------------------------------------------------------------------===// diff --git a/clang/include/clang/Frontend/CompilerInvocation.h b/clang/include/clang/Frontend/CompilerInvocation.h index 821336c32c1..e1af7b0d8da 100644 --- a/clang/include/clang/Frontend/CompilerInvocation.h +++ b/clang/include/clang/Frontend/CompilerInvocation.h @@ -14,6 +14,7 @@ #include "clang/Basic/TargetOptions.h" #include "clang/Basic/FileSystemOptions.h" #include "clang/Frontend/AnalyzerOptions.h" +#include "clang/Frontend/MigratorOptions.h" #include "clang/Frontend/CodeGenOptions.h" #include "clang/Frontend/DependencyOutputOptions.h" #include "clang/Frontend/DiagnosticOptions.h" @@ -56,6 +57,8 @@ class CompilerInvocation : public CompilerInvocationBase { /// Options controlling the static analyzer. AnalyzerOptions AnalyzerOpts; + MigratorOptions MigratorOpts; + /// Options controlling IRgen and the backend. CodeGenOptions CodeGenOpts; @@ -147,6 +150,11 @@ public: return AnalyzerOpts; } + MigratorOptions &getMigratorOpts() { return MigratorOpts; } + const MigratorOptions &getMigratorOpts() const { + return MigratorOpts; + } + CodeGenOptions &getCodeGenOpts() { return CodeGenOpts; } const CodeGenOptions &getCodeGenOpts() const { return CodeGenOpts; diff --git a/clang/include/clang/Frontend/MigratorOptions.h b/clang/include/clang/Frontend/MigratorOptions.h new file mode 100644 index 00000000000..23263d7aa03 --- /dev/null +++ b/clang/include/clang/Frontend/MigratorOptions.h @@ -0,0 +1,29 @@ +//===--- MigratorOptions.h - MigratorOptions Options ------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This header contains the structures necessary for a front-end to specify +// various migration analysis. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_CLANG_FRONTEND_MIGRATOROPTIONS +#define LLVM_CLANG_FRONTEND_MIGRATOROPTIONS + +namespace clang { + +class MigratorOptions { +public: + unsigned NoNSAllocReallocError : 1; + MigratorOptions() { + NoNSAllocReallocError = 0; + } +}; + +} +#endif 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; diff --git a/clang/test/ARCMT/GC-check-warn-nsalloc.m b/clang/test/ARCMT/GC-check-warn-nsalloc.m new file mode 100644 index 00000000000..5ce36c40d65 --- /dev/null +++ b/clang/test/ARCMT/GC-check-warn-nsalloc.m @@ -0,0 +1,12 @@ +// RUN: %clang_cc1 -arcmt-check -verify -no-ns-alloc-error -triple x86_64-apple-darwin10 -fobjc-gc-only %s +// RUN: %clang_cc1 -arcmt-check -verify -no-ns-alloc-error -triple x86_64-apple-darwin10 -fobjc-gc-only -x objective-c++ %s +// DISABLE: mingw32 +// rdar://10532541 +// XFAIL: * + +typedef unsigned NSUInteger; +void *__strong NSAllocateCollectable(NSUInteger size, NSUInteger options); + +void test1() { + NSAllocateCollectable(100, 0); // expected-warning {{call returns pointer to GC managed memory; it will become unmanaged in ARC}} +} |