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/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) {