|
17 | 17 | #include "clang/Driver/Compilation.h"
|
18 | 18 | #include "clang/Driver/Job.h"
|
19 | 19 | #include "clang/Driver/HostInfo.h"
|
| 20 | +#include "clang/Driver/ObjCRuntime.h" |
20 | 21 | #include "clang/Driver/Option.h"
|
21 | 22 | #include "clang/Driver/Options.h"
|
22 | 23 | #include "clang/Driver/ToolChain.h"
|
@@ -1600,47 +1601,6 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
|
1600 | 1601 | options::OPT_fno_lax_vector_conversions))
|
1601 | 1602 | CmdArgs.push_back("-fno-lax-vector-conversions");
|
1602 | 1603 |
|
1603 |
| - // Allow -fno-objc-arr to trump -fobjc-arr/-fobjc-arc. |
1604 |
| - // NOTE: This logic is duplicated in ToolChains.cpp. |
1605 |
| - bool ARC = isObjCAutoRefCount(Args); |
1606 |
| - if (ARC) { |
1607 |
| - CmdArgs.push_back("-fobjc-arc"); |
1608 |
| - |
1609 |
| - // Certain deployment targets don't have runtime support. |
1610 |
| - if (!getToolChain().HasARCRuntime()) |
1611 |
| - CmdArgs.push_back("-fobjc-no-arc-runtime"); |
1612 |
| - |
1613 |
| - // Allow the user to enable full exceptions code emission. |
1614 |
| - // We define off for Objective-CC, on for Objective-C++. |
1615 |
| - if (Args.hasFlag(options::OPT_fobjc_arc_exceptions, |
1616 |
| - options::OPT_fno_objc_arc_exceptions, |
1617 |
| - /*default*/ types::isCXX(InputType))) |
1618 |
| - CmdArgs.push_back("-fobjc-arc-exceptions"); |
1619 |
| - } |
1620 |
| - |
1621 |
| - // -fobjc-infer-related-result-type is the default, except in the Objective-C |
1622 |
| - // rewriter. |
1623 |
| - if (IsRewriter) |
1624 |
| - CmdArgs.push_back("-fno-objc-infer-related-result-type"); |
1625 |
| - |
1626 |
| - // Handle -fobjc-gc and -fobjc-gc-only. They are exclusive, and -fobjc-gc-only |
1627 |
| - // takes precedence. |
1628 |
| - const Arg *GCArg = Args.getLastArg(options::OPT_fobjc_gc_only); |
1629 |
| - if (!GCArg) |
1630 |
| - GCArg = Args.getLastArg(options::OPT_fobjc_gc); |
1631 |
| - if (GCArg) { |
1632 |
| - if (ARC) { |
1633 |
| - D.Diag(clang::diag::err_drv_objc_gc_arr) |
1634 |
| - << GCArg->getAsString(Args); |
1635 |
| - } else if (getToolChain().SupportsObjCGC()) { |
1636 |
| - GCArg->render(Args, CmdArgs); |
1637 |
| - } else { |
1638 |
| - // FIXME: We should move this to a hard error. |
1639 |
| - D.Diag(clang::diag::warn_drv_objc_gc_unsupported) |
1640 |
| - << GCArg->getAsString(Args); |
1641 |
| - } |
1642 |
| - } |
1643 |
| - |
1644 | 1604 | if (Args.getLastArg(options::OPT_fapple_kext))
|
1645 | 1605 | CmdArgs.push_back("-fapple-kext");
|
1646 | 1606 |
|
@@ -1805,17 +1765,23 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
|
1805 | 1765 | false))
|
1806 | 1766 | CmdArgs.push_back("-fgnu89-inline");
|
1807 | 1767 |
|
1808 |
| - // -fnext-runtime defaults to on Darwin and when rewriting Objective-C, and is |
1809 |
| - // -the -cc1 default. |
1810 |
| - bool NeXTRuntimeIsDefault = |
1811 |
| - IsRewriter || getToolChain().getTriple().getOS() == llvm::Triple::Darwin; |
1812 |
| - if (!Args.hasFlag(options::OPT_fnext_runtime, options::OPT_fgnu_runtime, |
1813 |
| - NeXTRuntimeIsDefault)) |
1814 |
| - CmdArgs.push_back("-fgnu-runtime"); |
1815 |
| - |
1816 | 1768 | // -fobjc-nonfragile-abi=0 is default.
|
| 1769 | + ObjCRuntime objCRuntime; |
1817 | 1770 | unsigned objcABIVersion = 0;
|
1818 | 1771 | if (types::isObjC(InputType)) {
|
| 1772 | + bool NeXTRuntimeIsDefault |
| 1773 | + = (IsRewriter || getToolChain().getTriple().isOSDarwin()); |
| 1774 | + if (Args.hasFlag(options::OPT_fnext_runtime, options::OPT_fgnu_runtime, |
| 1775 | + NeXTRuntimeIsDefault)) |
| 1776 | + objCRuntime.setKind(ObjCRuntime::NeXT); |
| 1777 | + else |
| 1778 | + objCRuntime.setKind(ObjCRuntime::GNU); |
| 1779 | + getToolChain().configureObjCRuntime(objCRuntime); |
| 1780 | + if (objCRuntime.HasARC) |
| 1781 | + CmdArgs.push_back("-fobjc-runtime-has-arc"); |
| 1782 | + if (objCRuntime.HasWeak) |
| 1783 | + CmdArgs.push_back("-fobjc-runtime-has-weak"); |
| 1784 | + |
1819 | 1785 | // Compute the Objective-C ABI "version" to use. Version numbers are
|
1820 | 1786 | // slightly confusing for historical reasons:
|
1821 | 1787 | // 1 - Traditional "fragile" ABI
|
@@ -1890,6 +1856,43 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
|
1890 | 1856 | #endif
|
1891 | 1857 | }
|
1892 | 1858 |
|
| 1859 | + // Allow -fno-objc-arr to trump -fobjc-arr/-fobjc-arc. |
| 1860 | + // NOTE: This logic is duplicated in ToolChains.cpp. |
| 1861 | + bool ARC = isObjCAutoRefCount(Args); |
| 1862 | + if (ARC) { |
| 1863 | + CmdArgs.push_back("-fobjc-arc"); |
| 1864 | + |
| 1865 | + // Allow the user to enable full exceptions code emission. |
| 1866 | + // We define off for Objective-CC, on for Objective-C++. |
| 1867 | + if (Args.hasFlag(options::OPT_fobjc_arc_exceptions, |
| 1868 | + options::OPT_fno_objc_arc_exceptions, |
| 1869 | + /*default*/ types::isCXX(InputType))) |
| 1870 | + CmdArgs.push_back("-fobjc-arc-exceptions"); |
| 1871 | + } |
| 1872 | + |
| 1873 | + // -fobjc-infer-related-result-type is the default, except in the Objective-C |
| 1874 | + // rewriter. |
| 1875 | + if (IsRewriter) |
| 1876 | + CmdArgs.push_back("-fno-objc-infer-related-result-type"); |
| 1877 | + |
| 1878 | + // Handle -fobjc-gc and -fobjc-gc-only. They are exclusive, and -fobjc-gc-only |
| 1879 | + // takes precedence. |
| 1880 | + const Arg *GCArg = Args.getLastArg(options::OPT_fobjc_gc_only); |
| 1881 | + if (!GCArg) |
| 1882 | + GCArg = Args.getLastArg(options::OPT_fobjc_gc); |
| 1883 | + if (GCArg) { |
| 1884 | + if (ARC) { |
| 1885 | + D.Diag(clang::diag::err_drv_objc_gc_arr) |
| 1886 | + << GCArg->getAsString(Args); |
| 1887 | + } else if (getToolChain().SupportsObjCGC()) { |
| 1888 | + GCArg->render(Args, CmdArgs); |
| 1889 | + } else { |
| 1890 | + // FIXME: We should move this to a hard error. |
| 1891 | + D.Diag(clang::diag::warn_drv_objc_gc_unsupported) |
| 1892 | + << GCArg->getAsString(Args); |
| 1893 | + } |
| 1894 | + } |
| 1895 | + |
1893 | 1896 | // Add exception args.
|
1894 | 1897 | addExceptionArgs(Args, InputType, getToolChain().getTriple(),
|
1895 | 1898 | KernelOrKext, IsRewriter, objcABIVersion, CmdArgs);
|
@@ -3237,8 +3240,12 @@ void darwin::Link::ConstructJob(Compilation &C, const JobAction &JA,
|
3237 | 3240 | // In ARC, if we don't have runtime support, link in the runtime
|
3238 | 3241 | // stubs. We have to do this *before* adding any of the normal
|
3239 | 3242 | // linker inputs so that its initializer gets run first.
|
3240 |
| - if (!getDarwinToolChain().HasARCRuntime() && isObjCAutoRefCount(Args)) |
3241 |
| - getDarwinToolChain().AddLinkARCArgs(Args, CmdArgs); |
| 3243 | + if (isObjCAutoRefCount(Args)) { |
| 3244 | + ObjCRuntime runtime; |
| 3245 | + getDarwinToolChain().configureObjCRuntime(runtime); |
| 3246 | + if (!runtime.HasARC) |
| 3247 | + getDarwinToolChain().AddLinkARCArgs(Args, CmdArgs); |
| 3248 | + } |
3242 | 3249 |
|
3243 | 3250 | AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs);
|
3244 | 3251 |
|
|
0 commit comments