diff options
author | John McCall <rjmccall@apple.com> | 2011-07-06 00:26:06 +0000 |
---|---|---|
committer | John McCall <rjmccall@apple.com> | 2011-07-06 00:26:06 +0000 |
commit | 9f084a3166b684573ba49df28fc5792bc37d92e1 (patch) | |
tree | d2976a87e54f0ef1014c769e44f86ab27212176f /lib/Driver | |
parent | 9670e179a67d868e171feac44fb8f9e2f108c5e8 (diff) |
Change the driver's logic about Objective-C runtimes: abstract out a
structure to hold inferred information, then propagate each invididual
bit down to -cc1. Separate the bits of "supports weak" and "has a native
ARC runtime"; make the latter a CodeGenOption.
The tool chain is still driving this decision, because it's the place that
has the required deployment target information on Darwin, but at least it's
better-factored now.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@134453 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Driver')
-rw-r--r-- | lib/Driver/Compilation.cpp | 1 | ||||
-rw-r--r-- | lib/Driver/ToolChain.cpp | 19 | ||||
-rw-r--r-- | lib/Driver/ToolChains.cpp | 12 | ||||
-rw-r--r-- | lib/Driver/ToolChains.h | 4 | ||||
-rw-r--r-- | lib/Driver/Tools.cpp | 109 |
5 files changed, 91 insertions, 54 deletions
diff --git a/lib/Driver/Compilation.cpp b/lib/Driver/Compilation.cpp index 2657faa0d3..e15e40295c 100644 --- a/lib/Driver/Compilation.cpp +++ b/lib/Driver/Compilation.cpp @@ -13,6 +13,7 @@ #include "clang/Driver/ArgList.h" #include "clang/Driver/Driver.h" #include "clang/Driver/DriverDiagnostic.h" +#include "clang/Driver/ObjCRuntime.h" #include "clang/Driver/Options.h" #include "clang/Driver/ToolChain.h" diff --git a/lib/Driver/ToolChain.cpp b/lib/Driver/ToolChain.cpp index cbbbc5c4de..0cce517549 100644 --- a/lib/Driver/ToolChain.cpp +++ b/lib/Driver/ToolChain.cpp @@ -15,7 +15,9 @@ #include "clang/Driver/Driver.h" #include "clang/Driver/DriverDiagnostic.h" #include "clang/Driver/HostInfo.h" +#include "clang/Driver/ObjCRuntime.h" #include "clang/Driver/Options.h" +#include "llvm/Support/ErrorHandling.h" using namespace clang::driver; @@ -47,6 +49,23 @@ bool ToolChain::HasNativeLLVMSupport() const { return false; } +void ToolChain::configureObjCRuntime(ObjCRuntime &runtime) const { + switch (runtime.getKind()) { + case ObjCRuntime::NeXT: + // Assume a minimal NeXT runtime. + runtime.HasARC = false; + runtime.HasWeak = false; + return; + + case ObjCRuntime::GNU: + // Assume a maximal GNU runtime. + runtime.HasARC = true; + runtime.HasWeak = true; + return; + } + llvm_unreachable("invalid runtime kind!"); +} + /// getARMTargetCPU - Get the (LLVM) name of the ARM cpu we are targeting. // // FIXME: tblgen this. diff --git a/lib/Driver/ToolChains.cpp b/lib/Driver/ToolChains.cpp index b4501acbb1..68ebc1b6b3 100644 --- a/lib/Driver/ToolChains.cpp +++ b/lib/Driver/ToolChains.cpp @@ -19,6 +19,7 @@ #include "clang/Driver/Driver.h" #include "clang/Driver/DriverDiagnostic.h" #include "clang/Driver/HostInfo.h" +#include "clang/Driver/ObjCRuntime.h" #include "clang/Driver/OptTable.h" #include "clang/Driver/Option.h" #include "clang/Driver/Options.h" @@ -74,8 +75,7 @@ bool Darwin::HasNativeLLVMSupport() const { return true; } -/// Darwin provides an ARC runtime starting in MacOS X 10.7 and iOS 5.0. -bool Darwin::HasARCRuntime() const { +bool Darwin::hasARCRuntime() const { // FIXME: Remove this once there is a proper way to detect an ARC runtime // for the simulator. switch (ARCRuntimeForSimulator) { @@ -93,6 +93,14 @@ bool Darwin::HasARCRuntime() const { return !isMacosxVersionLT(10, 7); } +/// Darwin provides an ARC runtime starting in MacOS X 10.7 and iOS 5.0. +void Darwin::configureObjCRuntime(ObjCRuntime &runtime) const { + if (runtime.getKind() != ObjCRuntime::NeXT) + return ToolChain::configureObjCRuntime(runtime); + + runtime.HasARC = runtime.HasWeak = hasARCRuntime(); +} + // FIXME: Can we tablegen this? static const char *GetArmArchForMArch(llvm::StringRef Value) { if (Value == "armv6k") diff --git a/lib/Driver/ToolChains.h b/lib/Driver/ToolChains.h index 9ed0dc2ef8..d68016b3a2 100644 --- a/lib/Driver/ToolChains.h +++ b/lib/Driver/ToolChains.h @@ -80,6 +80,8 @@ private: /// initialized. std::string MacosxVersionMin; + bool hasARCRuntime() const; + private: void AddDeploymentTarget(DerivedArgList &Args) const; @@ -184,7 +186,7 @@ public: virtual bool HasNativeLLVMSupport() const; - virtual bool HasARCRuntime() const; + virtual void configureObjCRuntime(ObjCRuntime &runtime) const; virtual DerivedArgList *TranslateArgs(const DerivedArgList &Args, const char *BoundArch) const; diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp index 4e70c5c372..d0fd914bf0 100644 --- a/lib/Driver/Tools.cpp +++ b/lib/Driver/Tools.cpp @@ -17,6 +17,7 @@ #include "clang/Driver/Compilation.h" #include "clang/Driver/Job.h" #include "clang/Driver/HostInfo.h" +#include "clang/Driver/ObjCRuntime.h" #include "clang/Driver/Option.h" #include "clang/Driver/Options.h" #include "clang/Driver/ToolChain.h" @@ -1600,47 +1601,6 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, options::OPT_fno_lax_vector_conversions)) CmdArgs.push_back("-fno-lax-vector-conversions"); - // Allow -fno-objc-arr to trump -fobjc-arr/-fobjc-arc. - // NOTE: This logic is duplicated in ToolChains.cpp. - bool ARC = isObjCAutoRefCount(Args); - if (ARC) { - CmdArgs.push_back("-fobjc-arc"); - - // Certain deployment targets don't have runtime support. - if (!getToolChain().HasARCRuntime()) - CmdArgs.push_back("-fobjc-no-arc-runtime"); - - // Allow the user to enable full exceptions code emission. - // We define off for Objective-CC, on for Objective-C++. - if (Args.hasFlag(options::OPT_fobjc_arc_exceptions, - options::OPT_fno_objc_arc_exceptions, - /*default*/ types::isCXX(InputType))) - CmdArgs.push_back("-fobjc-arc-exceptions"); - } - - // -fobjc-infer-related-result-type is the default, except in the Objective-C - // rewriter. - if (IsRewriter) - CmdArgs.push_back("-fno-objc-infer-related-result-type"); - - // Handle -fobjc-gc and -fobjc-gc-only. They are exclusive, and -fobjc-gc-only - // takes precedence. - const Arg *GCArg = Args.getLastArg(options::OPT_fobjc_gc_only); - if (!GCArg) - GCArg = Args.getLastArg(options::OPT_fobjc_gc); - if (GCArg) { - if (ARC) { - D.Diag(clang::diag::err_drv_objc_gc_arr) - << GCArg->getAsString(Args); - } else if (getToolChain().SupportsObjCGC()) { - GCArg->render(Args, CmdArgs); - } else { - // FIXME: We should move this to a hard error. - D.Diag(clang::diag::warn_drv_objc_gc_unsupported) - << GCArg->getAsString(Args); - } - } - if (Args.getLastArg(options::OPT_fapple_kext)) CmdArgs.push_back("-fapple-kext"); @@ -1805,17 +1765,23 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, false)) CmdArgs.push_back("-fgnu89-inline"); - // -fnext-runtime defaults to on Darwin and when rewriting Objective-C, and is - // -the -cc1 default. - bool NeXTRuntimeIsDefault = - IsRewriter || getToolChain().getTriple().getOS() == llvm::Triple::Darwin; - if (!Args.hasFlag(options::OPT_fnext_runtime, options::OPT_fgnu_runtime, - NeXTRuntimeIsDefault)) - CmdArgs.push_back("-fgnu-runtime"); - // -fobjc-nonfragile-abi=0 is default. + ObjCRuntime objCRuntime; unsigned objcABIVersion = 0; if (types::isObjC(InputType)) { + bool NeXTRuntimeIsDefault + = (IsRewriter || getToolChain().getTriple().isOSDarwin()); + if (Args.hasFlag(options::OPT_fnext_runtime, options::OPT_fgnu_runtime, + NeXTRuntimeIsDefault)) + objCRuntime.setKind(ObjCRuntime::NeXT); + else + objCRuntime.setKind(ObjCRuntime::GNU); + getToolChain().configureObjCRuntime(objCRuntime); + if (objCRuntime.HasARC) + CmdArgs.push_back("-fobjc-runtime-has-arc"); + if (objCRuntime.HasWeak) + CmdArgs.push_back("-fobjc-runtime-has-weak"); + // Compute the Objective-C ABI "version" to use. Version numbers are // slightly confusing for historical reasons: // 1 - Traditional "fragile" ABI @@ -1890,6 +1856,43 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, #endif } + // Allow -fno-objc-arr to trump -fobjc-arr/-fobjc-arc. + // NOTE: This logic is duplicated in ToolChains.cpp. + bool ARC = isObjCAutoRefCount(Args); + if (ARC) { + CmdArgs.push_back("-fobjc-arc"); + + // Allow the user to enable full exceptions code emission. + // We define off for Objective-CC, on for Objective-C++. + if (Args.hasFlag(options::OPT_fobjc_arc_exceptions, + options::OPT_fno_objc_arc_exceptions, + /*default*/ types::isCXX(InputType))) + CmdArgs.push_back("-fobjc-arc-exceptions"); + } + + // -fobjc-infer-related-result-type is the default, except in the Objective-C + // rewriter. + if (IsRewriter) + CmdArgs.push_back("-fno-objc-infer-related-result-type"); + + // Handle -fobjc-gc and -fobjc-gc-only. They are exclusive, and -fobjc-gc-only + // takes precedence. + const Arg *GCArg = Args.getLastArg(options::OPT_fobjc_gc_only); + if (!GCArg) + GCArg = Args.getLastArg(options::OPT_fobjc_gc); + if (GCArg) { + if (ARC) { + D.Diag(clang::diag::err_drv_objc_gc_arr) + << GCArg->getAsString(Args); + } else if (getToolChain().SupportsObjCGC()) { + GCArg->render(Args, CmdArgs); + } else { + // FIXME: We should move this to a hard error. + D.Diag(clang::diag::warn_drv_objc_gc_unsupported) + << GCArg->getAsString(Args); + } + } + // Add exception args. addExceptionArgs(Args, InputType, getToolChain().getTriple(), KernelOrKext, IsRewriter, objcABIVersion, CmdArgs); @@ -3237,8 +3240,12 @@ void darwin::Link::ConstructJob(Compilation &C, const JobAction &JA, // In ARC, if we don't have runtime support, link in the runtime // stubs. We have to do this *before* adding any of the normal // linker inputs so that its initializer gets run first. - if (!getDarwinToolChain().HasARCRuntime() && isObjCAutoRefCount(Args)) - getDarwinToolChain().AddLinkARCArgs(Args, CmdArgs); + if (isObjCAutoRefCount(Args)) { + ObjCRuntime runtime; + getDarwinToolChain().configureObjCRuntime(runtime); + if (!runtime.HasARC) + getDarwinToolChain().AddLinkARCArgs(Args, CmdArgs); + } AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs); |