[cfe-commits] r148887 - in /cfe/trunk: include/clang/Driver/CC1Options.td include/clang/Frontend/CompilerInvocation.h include/clang/Frontend/MigratorOptions.h lib/ARCMigrate/ARCMT.cpp lib/ARCMigrate/Internals.h lib/ARCMigrate/TransGCCalls.cpp lib/ARCMigrate/TransformActions.cpp lib/Frontend/CompilerInvocation.cpp test/ARCMT/GC-check-warn-nsalloc.m

Aaron Ballman aaron at aaronballman.com
Mon May 19 08:29:03 PDT 2014


Sorry to resurrect an ancient commit, but... (comment inline)

On Tue, Jan 24, 2012 at 7:20 PM, Fariborz Jahanian <fjahanian at apple.com> wrote:
> Author: fjahanian
> Date: Tue Jan 24 18:20:29 2012
> New Revision: 148887
>
> URL: http://llvm.org/viewvc/llvm-project?rev=148887&view=rev
> Log:
> 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
>
> Added:
>     cfe/trunk/include/clang/Frontend/MigratorOptions.h
>     cfe/trunk/test/ARCMT/GC-check-warn-nsalloc.m
> Modified:
>     cfe/trunk/include/clang/Driver/CC1Options.td
>     cfe/trunk/include/clang/Frontend/CompilerInvocation.h
>     cfe/trunk/lib/ARCMigrate/ARCMT.cpp
>     cfe/trunk/lib/ARCMigrate/Internals.h
>     cfe/trunk/lib/ARCMigrate/TransGCCalls.cpp
>     cfe/trunk/lib/ARCMigrate/TransformActions.cpp
>     cfe/trunk/lib/Frontend/CompilerInvocation.cpp
>
> Modified: cfe/trunk/include/clang/Driver/CC1Options.td
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/CC1Options.td?rev=148887&r1=148886&r2=148887&view=diff
> ==============================================================================
> --- cfe/trunk/include/clang/Driver/CC1Options.td (original)
> +++ cfe/trunk/include/clang/Driver/CC1Options.td Tue Jan 24 18:20:29 2012
> @@ -101,6 +101,12 @@
>    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
>  //===----------------------------------------------------------------------===//
>
>
> Modified: cfe/trunk/include/clang/Frontend/CompilerInvocation.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/CompilerInvocation.h?rev=148887&r1=148886&r2=148887&view=diff
> ==============================================================================
> --- cfe/trunk/include/clang/Frontend/CompilerInvocation.h (original)
> +++ cfe/trunk/include/clang/Frontend/CompilerInvocation.h Tue Jan 24 18:20:29 2012
> @@ -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 @@
>    /// Options controlling the static analyzer.
>    AnalyzerOptions AnalyzerOpts;
>
> +  MigratorOptions MigratorOpts;
> +
>    /// Options controlling IRgen and the backend.
>    CodeGenOptions CodeGenOpts;
>
> @@ -147,6 +150,11 @@
>      return AnalyzerOpts;
>    }
>
> +  MigratorOptions &getMigratorOpts() { return MigratorOpts; }
> +  const MigratorOptions &getMigratorOpts() const {
> +    return MigratorOpts;
> +  }
> +
>    CodeGenOptions &getCodeGenOpts() { return CodeGenOpts; }
>    const CodeGenOptions &getCodeGenOpts() const {
>      return CodeGenOpts;
>
> Added: cfe/trunk/include/clang/Frontend/MigratorOptions.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/MigratorOptions.h?rev=148887&view=auto
> ==============================================================================
> --- cfe/trunk/include/clang/Frontend/MigratorOptions.h (added)
> +++ cfe/trunk/include/clang/Frontend/MigratorOptions.h Tue Jan 24 18:20:29 2012
> @@ -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
>
> Modified: cfe/trunk/lib/ARCMigrate/ARCMT.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ARCMigrate/ARCMT.cpp?rev=148887&r1=148886&r2=148887&view=diff
> ==============================================================================
> --- cfe/trunk/lib/ARCMigrate/ARCMT.cpp (original)
> +++ cfe/trunk/lib/ARCMigrate/ARCMT.cpp Tue Jan 24 18:20:29 2012
> @@ -229,6 +229,7 @@
>      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 @@
>
>    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);
>
> Modified: cfe/trunk/lib/ARCMigrate/Internals.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ARCMigrate/Internals.h?rev=148887&r1=148886&r2=148887&view=diff
> ==============================================================================
> --- cfe/trunk/lib/ARCMigrate/Internals.h (original)
> +++ cfe/trunk/lib/ARCMigrate/Internals.h Tue Jan 24 18:20:29 2012
> @@ -94,6 +94,8 @@
>
>    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 @@
>  public:
>    ASTContext &Ctx;
>    LangOptions::GCMode OrigGCMode;
> +  MigratorOptions MigOptions;
>    Sema &SemaRef;
>    TransformActions &TA;
>    std::vector<SourceLocation> &ARCMTMacroLocs;
> @@ -145,10 +148,13 @@
>    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() {
>
> Modified: cfe/trunk/lib/ARCMigrate/TransGCCalls.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ARCMigrate/TransGCCalls.cpp?rev=148887&r1=148886&r2=148887&view=diff
> ==============================================================================
> --- cfe/trunk/lib/ARCMigrate/TransGCCalls.cpp (original)
> +++ cfe/trunk/lib/ARCMigrate/TransGCCalls.cpp Tue Jan 24 18:20:29 2012
> @@ -38,9 +38,14 @@
>      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;
>      }
>
>
> Modified: cfe/trunk/lib/ARCMigrate/TransformActions.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ARCMigrate/TransformActions.cpp?rev=148887&r1=148886&r2=148887&view=diff
> ==============================================================================
> --- cfe/trunk/lib/ARCMigrate/TransformActions.cpp (original)
> +++ cfe/trunk/lib/ARCMigrate/TransformActions.cpp Tue Jan 24 18:20:29 2012
> @@ -692,6 +692,25 @@
>    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() &&
>
> Modified: cfe/trunk/lib/Frontend/CompilerInvocation.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInvocation.cpp?rev=148887&r1=148886&r2=148887&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Frontend/CompilerInvocation.cpp (original)
> +++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp Tue Jan 24 18:20:29 2012
> @@ -1053,6 +1053,11 @@
>    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 @@
>    }
>
>    Success = ParseAnalyzerArgs(Res.getAnalyzerOpts(), *Args, Diags) && Success;
> +  Success = ParseMigratorArgs(Res.getMigratorOpts(), *Args) && Success;
>    ParseDependencyOutputArgs(Res.getDependencyOutputOpts(), *Args);
>    Success = ParseDiagnosticArgs(Res.getDiagnosticOpts(), *Args, Diags)
>              && Success;
>
> Added: cfe/trunk/test/ARCMT/GC-check-warn-nsalloc.m
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ARCMT/GC-check-warn-nsalloc.m?rev=148887&view=auto
> ==============================================================================
> --- cfe/trunk/test/ARCMT/GC-check-warn-nsalloc.m (added)
> +++ cfe/trunk/test/ARCMT/GC-check-warn-nsalloc.m Tue Jan 24 18:20:29 2012
> @@ -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: *

This is the only test for this change, and it's XFAILed for all
targets, with no explanation as to why. When I remove the XFAIL, I get
asserts on Windows because of the call to setDiagnosticMapping. Was
that the reason this was XFAILed? Were there plans to fix this?

> +
> +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}}
> +}

~Aaron



More information about the cfe-commits mailing list