Driver/Objective-C: Retool Objective-C ABI flags to be more usable, and actually
document behavior. Will wonders never cease.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@114334 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/docs/tools/clang.pod b/docs/tools/clang.pod
index 8284d31..8a43731 100644
--- a/docs/tools/clang.pod
+++ b/docs/tools/clang.pod
@@ -191,7 +191,6 @@
Enable the "Blocks" language feature.
-
=item B<-fobjc-gc-only>
Indicate that Objective-C code should be compiled in GC-only mode, which only
@@ -202,6 +201,22 @@
Indicate that Objective-C code should be compiled in hybrid-GC mode, which works
with both GC and non-GC mode.
+=item B<-fobjc-abi-version>=I<version>
+
+Select the Objective-C ABI version to use. Available versions are 1 (legacy
+"fragile" ABI), 2 (non-fragile ABI 1), and 3 (non-fragile ABI 2).
+
+=item B<-fobjc-nonfragile-abi-version>=I<version>
+
+Select the Objective-C non-fragile ABI version to use by default. This will only
+be used as the Objective-C ABI when the non-fragile ABI is enabled (either via
+-fobjc-nonfragile-abi, or because it is the platform default).
+
+=item B<-fobjc-nonfragile-abi>
+
+Enable use of the Objective-C non-fragile ABI. On platforms for which this is
+the default ABI, it can be disabled with B<-fno-objc-nonfragile-abi>.
+
=back
diff --git a/include/clang/Driver/Options.td b/include/clang/Driver/Options.td
index 8b78220..6451e4c 100644
--- a/include/clang/Driver/Options.td
+++ b/include/clang/Driver/Options.td
@@ -342,15 +342,19 @@
def fno_verbose_asm : Flag<"-fno-verbose-asm">, Group<f_Group>;
def fno_working_directory : Flag<"-fno-working-directory">, Group<f_Group>;
def fno_zero_initialized_in_bss : Flag<"-fno-zero-initialized-in-bss">, Group<f_Group>;
-def fobjc_abi_version_EQ : Joined<"-fobjc-abi-version=">, Group<f_Group>;
def fobjc_atdefs : Flag<"-fobjc-atdefs">, Group<clang_ignored_f_Group>;
def fobjc_call_cxx_cdtors : Flag<"-fobjc-call-cxx-cdtors">, Group<clang_ignored_f_Group>;
def fobjc_gc_only : Flag<"-fobjc-gc-only">, Group<f_Group>;
def fobjc_gc : Flag<"-fobjc-gc">, Group<f_Group>;
def fobjc_legacy_dispatch : Flag<"-fobjc-legacy-dispatch">, Group<f_Group>;
def fobjc_new_property : Flag<"-fobjc-new-property">, Group<clang_ignored_f_Group>;
+
+// Objective-C ABI options.
+def fobjc_abi_version_EQ : Joined<"-fobjc-abi-version=">, Group<f_Group>;
+def fobjc_nonfragile_abi_version_EQ : Joined<"-fobjc-nonfragile-abi-version=">, Group<f_Group>;
def fobjc_nonfragile_abi : Flag<"-fobjc-nonfragile-abi">, Group<f_Group>;
-def fobjc_nonfragile_abi2 : Flag<"-fobjc-nonfragile-abi2">, Group<f_Group>;
+def fno_objc_nonfragile_abi : Flag<"-fno-objc-nonfragile-abi">, Group<f_Group>;
+
def fobjc_sender_dependent_dispatch : Flag<"-fobjc-sender-dependent-dispatch">, Group<f_Group>;
def fobjc : Flag<"-fobjc">, Group<f_Group>;
def fomit_frame_pointer : Flag<"-fomit-frame-pointer">, Group<f_Group>;
diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp
index 58f5565..bfb42d8 100644
--- a/lib/Driver/Tools.cpp
+++ b/lib/Driver/Tools.cpp
@@ -1287,12 +1287,13 @@
// -fobjc-nonfragile-abi=0 is default.
if (types::isObjC(InputType)) {
+ // Compute the Objective-C ABI "version" to use. Version numbers are
+ // slightly confusing for historical reasons:
+ // 1 - Traditional "fragile" ABI
+ // 2 - Non-fragile ABI, version 1
+ // 3 - Non-fragile ABI, version 2
unsigned Version = 1;
- if (Args.hasArg(options::OPT_fobjc_nonfragile_abi))
- Version = 2;
- else if (Args.hasArg(options::OPT_fobjc_nonfragile_abi2) ||
- getToolChain().IsObjCNonFragileABIDefault())
- Version = 3;
+ // If -fobjc-abi-version= is present, use that to set the version.
if (Arg *A = Args.getLastArg(options::OPT_fobjc_abi_version_EQ)) {
if (llvm::StringRef(A->getValue(Args)) == "1")
Version = 1;
@@ -1302,6 +1303,29 @@
Version = 3;
else
D.Diag(clang::diag::err_drv_clang_unsupported) << A->getAsString(Args);
+ } else {
+ // Otherwise, determine if we are using the non-fragile ABI.
+ if (Args.hasFlag(options::OPT_fobjc_nonfragile_abi,
+ options::OPT_fno_objc_nonfragile_abi,
+ getToolChain().IsObjCNonFragileABIDefault())) {
+ // Determine the non-fragile ABI version to use.
+ unsigned NonFragileABIVersion = 2;
+
+ if (Arg *A = Args.getLastArg(
+ options::OPT_fobjc_nonfragile_abi_version_EQ)) {
+ if (llvm::StringRef(A->getValue(Args)) == "1")
+ NonFragileABIVersion = 1;
+ else if (llvm::StringRef(A->getValue(Args)) == "2")
+ NonFragileABIVersion = 2;
+ else
+ D.Diag(clang::diag::err_drv_clang_unsupported)
+ << A->getAsString(Args);
+ }
+
+ Version = 1 + NonFragileABIVersion;
+ } else {
+ Version = 1;
+ }
}
if (Version == 2 || Version == 3) {