From f19c8901645037dcf8fb45a3d3ae25653a40df78 Mon Sep 17 00:00:00 2001
From: Fariborz Jahanian <fjahanian@apple.com>
Date: Mon, 20 Jan 2014 19:32:33 +0000
Subject: [PATCH 1007/1012] reinstate -fno-objc-legacy-dispatch behavior when
 the deployment target is 10.5 or earlier

<rdar://problem/18971940>

Squashes three cherry-picks from trunk into release_34 branch:

ObjectiveC driver. reinstate -fno-objc-legacy-dispatch behavior
when the deployment target is 10.5. // rdar://15852259

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@199682 91177308-0d34-0410-b5e6-96231b3b80d8
(cherry picked from commit 015f92d36592bf95f6a71a24b64031479a990d35)

ObjectiveC driver. change to reinstate -fno-objc-legacy-dispatch behavior
when the deployment target is 10.5. // rdar://15852259

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@199780 91177308-0d34-0410-b5e6-96231b3b80d8
(cherry picked from commit 69da841e85785ea625467e23804f6a9dd376528b)

Objective-C driver. Do not use legacy dispatch for
10.5 or less for x86_64 arch. // rdar://15852259

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@200854 91177308-0d34-0410-b5e6-96231b3b80d8
(cherry picked from commit 3bb54680c4b6e7d918c82e96ecd56239e3149a5a)
---
 include/clang/Basic/ObjCRuntime.h  | 5 +++++
 lib/Driver/Tools.cpp               | 7 ++++---
 test/Driver/darwin-objc-defaults.m | 9 +++++++++
 3 files changed, 18 insertions(+), 3 deletions(-)

diff --git llvm_release_34/tools/clang/include/clang/Basic/ObjCRuntime.h macports_release_34/tools/clang/include/clang/Basic/ObjCRuntime.h
index 4c64497..fa375f4 100644
--- llvm_release_34/tools/clang/include/clang/Basic/ObjCRuntime.h
+++ macports_release_34/tools/clang/include/clang/Basic/ObjCRuntime.h
@@ -99,6 +99,11 @@ public:
           Arch == llvm::Triple::x86_64)
         return false;
     }
+    else if ((getKind() ==  MacOSX) && isNonFragile() &&
+             (getVersion() >= VersionTuple(10, 0)) &&
+             (getVersion() < VersionTuple(10, 6)))
+        return Arch != llvm::Triple::x86_64;
+    // Except for deployment target of 10.5 or less,
     // Mac runtimes use legacy dispatch everywhere now.
     return true;
   }
diff --git llvm_release_34/tools/clang/lib/Driver/Tools.cpp macports_release_34/tools/clang/lib/Driver/Tools.cpp
index f8d1695..09c5c9a 100644
--- llvm_release_34/tools/clang/lib/Driver/Tools.cpp
+++ macports_release_34/tools/clang/lib/Driver/Tools.cpp
@@ -3361,9 +3361,10 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
   ObjCRuntime objcRuntime = AddObjCRuntimeArgs(Args, CmdArgs, rewriteKind);
 
   // -fobjc-dispatch-method is only relevant with the nonfragile-abi, and
-  // legacy is the default. Next runtime is always legacy dispatch and
-  // -fno-objc-legacy-dispatch gets ignored silently.
-  if (objcRuntime.isNonFragile() && !objcRuntime.isNeXTFamily()) {
+  // legacy is the default. Except for deployment taget of 10.5,
+  // next runtime is always legacy dispatch and -fno-objc-legacy-dispatch
+  // gets ignored silently.
+  if (objcRuntime.isNonFragile()) {
     if (!Args.hasFlag(options::OPT_fobjc_legacy_dispatch,
                       options::OPT_fno_objc_legacy_dispatch,
                       objcRuntime.isLegacyDispatchDefaultForArch(
diff --git llvm_release_34/tools/clang/test/Driver/darwin-objc-defaults.m macports_release_34/tools/clang/test/Driver/darwin-objc-defaults.m
index 1742deb..1b3f7a8 100644
--- llvm_release_34/tools/clang/test/Driver/darwin-objc-defaults.m
+++ macports_release_34/tools/clang/test/Driver/darwin-objc-defaults.m
@@ -32,11 +32,20 @@
 // x86_64
 
 // RUN: %clang -target x86_64-apple-darwin10 -S -### %s \
+// RUN:   -arch x86_64 -mmacosx-version-min=10.4 2> %t
+// RUN: FileCheck --check-prefix CHECK-CHECK-X86_64_OSX10_4 < %t %s
+
+// CHECK-CHECK-X86_64_OSX10_4: "-cc1"
+// CHECK-CHECK-X86_64_OSX10_4: -fobjc-dispatch-method=non-legacy
+
+// RUN: %clang -target x86_64-apple-darwin10 -S -### %s \
 // RUN:   -arch x86_64 -mmacosx-version-min=10.5 2> %t
 // RUN: FileCheck --check-prefix CHECK-CHECK-X86_64_OSX10_5 < %t %s
 
+
 // CHECK-CHECK-X86_64_OSX10_5: "-cc1"
 // CHECK-CHECK-X86_64_OSX10_5: -fobjc-runtime=macosx-10.5
+// CHECK-CHECK-X86_64_OSX10_5: -fobjc-dispatch-method=non-legacy
 // CHECK-CHECK-X86_64_OSX10_5: darwin-objc-defaults
 
 // RUN: %clang -target x86_64-apple-darwin10 -S -### %s \
-- 
2.10.1

