diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td b/clang/include/clang/Basic/DiagnosticDriverKinds.td index 021de8869e45f6cfe081c78d9cb9001cbcd38933..aaf524105637f0fdbbaa259805e4af84ea74882f 100644 --- a/clang/include/clang/Basic/DiagnosticDriverKinds.td +++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td @@ -93,6 +93,8 @@ def err_drv_objc_gc_arr : Error< "cannot specify both '-fobjc-arc' and '%0'">; def err_arc_nonfragile_abi : Error< "-fobjc-arc is not supported with fragile abi">; +def err_arc_unsupported : Error< + "-fobjc-arc is not supported on current deployment target">; def err_drv_mg_requires_m_or_mm : Error< "option '-MG' requires '-M' or '-MM'">; diff --git a/clang/include/clang/Driver/ToolChain.h b/clang/include/clang/Driver/ToolChain.h index 4f3a3be68136bf996d8dc36bcbcdcebd324ff673..c35cf673dee495ea8cffa37cdba17249d70419dd 100644 --- a/clang/include/clang/Driver/ToolChain.h +++ b/clang/include/clang/Driver/ToolChain.h @@ -184,6 +184,9 @@ public: /// Does this tool chain support Objective-C garbage collection. virtual bool SupportsObjCGC() const { return true; } + /// Does this tool chain support Objective-C ARC. + virtual bool SupportsObjCARC() const { return true; } + /// UseDwarfDebugFlags - Embed the compile options to clang into the Dwarf /// compile unit information. virtual bool UseDwarfDebugFlags() const { return false; } diff --git a/clang/lib/Driver/ToolChains.cpp b/clang/lib/Driver/ToolChains.cpp index 14c87d8216f3f0bc7e39fd8968842969aa657eba..e125ab78f4e10eba764eedf4b9b576e7c0feda1e 100644 --- a/clang/lib/Driver/ToolChains.cpp +++ b/clang/lib/Driver/ToolChains.cpp @@ -1019,6 +1019,10 @@ bool Darwin::SupportsObjCGC() const { return !isTargetIPhoneOS(); } +bool Darwin::SupportsObjCARC() const { + return isTargetIPhoneOS() || !isMacosxVersionLT(10, 6); +} + std::string Darwin_Generic_GCC::ComputeEffectiveClangTriple(const ArgList &Args, types::ID InputType) const { diff --git a/clang/lib/Driver/ToolChains.h b/clang/lib/Driver/ToolChains.h index 0fb213828ff9e6780637e0c0864b6d7caea5eb1b..0d591107de81dbd61886dba25612195ce60cec49 100644 --- a/clang/lib/Driver/ToolChains.h +++ b/clang/lib/Driver/ToolChains.h @@ -379,6 +379,8 @@ public: virtual bool SupportsObjCGC() const; + virtual bool SupportsObjCARC() const; + virtual bool UseDwarfDebugFlags() const; virtual bool UseSjLjExceptions() const; diff --git a/clang/lib/Driver/Tools.cpp b/clang/lib/Driver/Tools.cpp index 14fb9cb7188e3449d2e60a367ed7065f535e2413..c5caaf024f73fe14e7eb973ab4a35b39a4a02aea 100644 --- a/clang/lib/Driver/Tools.cpp +++ b/clang/lib/Driver/Tools.cpp @@ -2225,6 +2225,9 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, // NOTE: This logic is duplicated in ToolChains.cpp. bool ARC = isObjCAutoRefCount(Args); if (ARC) { + if (!getToolChain().SupportsObjCARC()) + D.Diag(diag::err_arc_unsupported); + CmdArgs.push_back("-fobjc-arc"); // FIXME: It seems like this entire block, and several around it should be diff --git a/clang/test/Driver/arc.c b/clang/test/Driver/arc.c index 96f03656e6ea4b6dca10e1eab1a983b231aa58a9..f2c1127116a057a846880eda3e4596641801bee7 100644 --- a/clang/test/Driver/arc.c +++ b/clang/test/Driver/arc.c @@ -1,8 +1,9 @@ -// RUN: %clang -ObjC -target i386-apple-darwin9 -m32 -fobjc-arc %s -fsyntax-only 2>&1 | FileCheck %s -// RUN: %clang -x objective-c -target i386-apple-darwin9 -m32 -fobjc-arc %s -fsyntax-only 2>&1 | FileCheck %s -// RUN: %clang -x objective-c++ -target i386-apple-darwin9 -m32 -fobjc-arc %s -fsyntax-only 2>&1 | FileCheck %s -// RUN: %clang -x c -target i386-apple-darwin9 -m32 -fobjc-arc %s -fsyntax-only 2>&1 | FileCheck -check-prefix NOTOBJC %s -// RUN: %clang -x c++ -target i386-apple-darwin9 -m32 -fobjc-arc %s -fsyntax-only 2>&1 | FileCheck -check-prefix NOTOBJC %s +// RUN: %clang -ObjC -target i386-apple-darwin10 -m32 -fobjc-arc %s -fsyntax-only 2>&1 | FileCheck %s +// RUN: %clang -x objective-c -target i386-apple-darwin10 -m32 -fobjc-arc %s -fsyntax-only 2>&1 | FileCheck %s +// RUN: %clang -x objective-c++ -target i386-apple-darwin10 -m32 -fobjc-arc %s -fsyntax-only 2>&1 | FileCheck %s +// RUN: %clang -x c -target i386-apple-darwin10 -m32 -fobjc-arc %s -fsyntax-only 2>&1 | FileCheck -check-prefix NOTOBJC %s +// RUN: %clang -x c++ -target i386-apple-darwin10 -m32 -fobjc-arc %s -fsyntax-only 2>&1 | FileCheck -check-prefix NOTOBJC %s +// RUN: %clang -x objective-c -target x86_64-apple-darwin11 -mmacosx-version-min=10.5 -fobjc-arc %s -fsyntax-only 2>&1 | FileCheck -check-prefix UNSUPPORTED %s // Just to test clang is working. # foo @@ -12,3 +13,5 @@ // NOTOBJC-NOT: error: -fobjc-arc is not supported with fragile abi // NOTOBJC: invalid preprocessing directive + +// UNSUPPORTED: error: -fobjc-arc is not supported on current deployment target