[clang] ObjcRuntime.h: Add mips64, aarch64, and riscv64 to non-legacy dispatch (PR #76694)

Hugo Melder via cfe-commits cfe-commits at lists.llvm.org
Tue Jan 2 12:45:23 PST 2024


https://github.com/hmelder updated https://github.com/llvm/llvm-project/pull/76694

>From 97a9a2753c52d6b377d929a4a6e717ab3c69b68d Mon Sep 17 00:00:00 2001
From: hmelder <service at hugomelder.com>
Date: Tue, 2 Jan 2024 01:46:19 +0100
Subject: [PATCH 1/4] Add mips64, aarch64, and riscv64 to ObjcRuntime dispatch

---
 clang/include/clang/Basic/ObjCRuntime.h | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/clang/include/clang/Basic/ObjCRuntime.h b/clang/include/clang/Basic/ObjCRuntime.h
index 500b2462f00773..29392ad0a0f577 100644
--- a/clang/include/clang/Basic/ObjCRuntime.h
+++ b/clang/include/clang/Basic/ObjCRuntime.h
@@ -101,10 +101,17 @@ class ObjCRuntime {
     // The GNUstep runtime uses a newer dispatch method by default from
     // version 1.6 onwards
     if (getKind() == GNUstep && getVersion() >= VersionTuple(1, 6)) {
-      if (Arch == llvm::Triple::arm ||
-          Arch == llvm::Triple::x86 ||
-          Arch == llvm::Triple::x86_64)
-        return false;
+      switch (Arch) {
+        case llvm::Triple::arm:
+        case llvm::Triple::x86:
+        case llvm::Triple::x86_64:
+        case llvm::Triple::aarch64:
+        case llvm::Triple::mips64:
+        case llvm::Triple::riscv64:
+          return false;
+        default:
+          return true;
+      }
     }
     else if ((getKind() ==  MacOSX) && isNonFragile() &&
              (getVersion() >= VersionTuple(10, 0)) &&

>From c9dd0b77456302fddcb9ee4904db2f667e946850 Mon Sep 17 00:00:00 2001
From: hmelder <service at hugomelder.com>
Date: Tue, 2 Jan 2024 01:54:40 +0100
Subject: [PATCH 2/4] ObjcRuntime.h: Adjust formatting

---
 clang/include/clang/Basic/ObjCRuntime.h | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/clang/include/clang/Basic/ObjCRuntime.h b/clang/include/clang/Basic/ObjCRuntime.h
index 29392ad0a0f577..adfc04e3bd2d29 100644
--- a/clang/include/clang/Basic/ObjCRuntime.h
+++ b/clang/include/clang/Basic/ObjCRuntime.h
@@ -102,15 +102,15 @@ class ObjCRuntime {
     // version 1.6 onwards
     if (getKind() == GNUstep && getVersion() >= VersionTuple(1, 6)) {
       switch (Arch) {
-        case llvm::Triple::arm:
-        case llvm::Triple::x86:
-        case llvm::Triple::x86_64:
-        case llvm::Triple::aarch64:
-        case llvm::Triple::mips64:
-        case llvm::Triple::riscv64:
-          return false;
-        default:
-          return true;
+      case llvm::Triple::arm:
+      case llvm::Triple::x86:
+      case llvm::Triple::x86_64:
+      case llvm::Triple::aarch64:
+      case llvm::Triple::mips64:
+      case llvm::Triple::riscv64:
+        return false;
+      default:
+        return true;
       }
     }
     else if ((getKind() ==  MacOSX) && isNonFragile() &&

>From 7c69da720afc45f6d2e3b7e2cc62f09a257289da Mon Sep 17 00:00:00 2001
From: hmelder <service at hugomelder.com>
Date: Tue, 2 Jan 2024 21:41:33 +0100
Subject: [PATCH 3/4] ObjCRuntime: format and update dispatch archs

---
 clang/include/clang/Basic/ObjCRuntime.h | 213 +++++++++++++++---------
 1 file changed, 133 insertions(+), 80 deletions(-)

diff --git a/clang/include/clang/Basic/ObjCRuntime.h b/clang/include/clang/Basic/ObjCRuntime.h
index adfc04e3bd2d29..c368b6f3bf3b24 100644
--- a/clang/include/clang/Basic/ObjCRuntime.h
+++ b/clang/include/clang/Basic/ObjCRuntime.h
@@ -81,13 +81,20 @@ class ObjCRuntime {
   /// "non-fragile" ABI?
   bool isNonFragile() const {
     switch (getKind()) {
-    case FragileMacOSX: return false;
-    case GCC: return false;
-    case MacOSX: return true;
-    case GNUstep: return true;
-    case ObjFW: return true;
-    case iOS: return true;
-    case WatchOS: return true;
+    case FragileMacOSX:
+      return false;
+    case GCC:
+      return false;
+    case MacOSX:
+      return true;
+    case GNUstep:
+      return true;
+    case ObjFW:
+      return true;
+    case iOS:
+      return true;
+    case WatchOS:
+      return true;
     }
     llvm_unreachable("bad kind");
   }
@@ -100,23 +107,24 @@ class ObjCRuntime {
   bool isLegacyDispatchDefaultForArch(llvm::Triple::ArchType Arch) {
     // The GNUstep runtime uses a newer dispatch method by default from
     // version 1.6 onwards
-    if (getKind() == GNUstep && getVersion() >= VersionTuple(1, 6)) {
+    if (getKind() == GNUstep) {
       switch (Arch) {
       case llvm::Triple::arm:
       case llvm::Triple::x86:
       case llvm::Triple::x86_64:
+        return !(getVersion() >= VersionTuple(1, 6));
       case llvm::Triple::aarch64:
       case llvm::Triple::mips64:
+        return !(getVersion() >= VersionTuple(1, 9));
       case llvm::Triple::riscv64:
-        return false;
+        return !(getVersion() >= VersionTuple(2, 2));
       default:
         return true;
       }
-    }
-    else if ((getKind() ==  MacOSX) && isNonFragile() &&
-             (getVersion() >= VersionTuple(10, 0)) &&
-             (getVersion() < VersionTuple(10, 6)))
-        return Arch != llvm::Triple::x86_64;
+    } 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;
@@ -151,12 +159,18 @@ class ObjCRuntime {
     case FragileMacOSX:
       // No stub library for the fragile runtime.
       return getVersion() >= VersionTuple(10, 7);
-    case MacOSX: return true;
-    case iOS: return true;
-    case WatchOS: return true;
-    case GCC: return false;
-    case GNUstep: return true;
-    case ObjFW: return true;
+    case MacOSX:
+      return true;
+    case iOS:
+      return true;
+    case WatchOS:
+      return true;
+    case GCC:
+      return false;
+    case GNUstep:
+      return true;
+    case ObjFW:
+      return true;
     }
     llvm_unreachable("bad kind");
   }
@@ -168,14 +182,21 @@ class ObjCRuntime {
   /// library.
   bool hasNativeARC() const {
     switch (getKind()) {
-    case FragileMacOSX: return getVersion() >= VersionTuple(10, 7);
-    case MacOSX: return getVersion() >= VersionTuple(10, 7);
-    case iOS: return getVersion() >= VersionTuple(5);
-    case WatchOS: return true;
-
-    case GCC: return false;
-    case GNUstep: return getVersion() >= VersionTuple(1, 6);
-    case ObjFW: return true;
+    case FragileMacOSX:
+      return getVersion() >= VersionTuple(10, 7);
+    case MacOSX:
+      return getVersion() >= VersionTuple(10, 7);
+    case iOS:
+      return getVersion() >= VersionTuple(5);
+    case WatchOS:
+      return true;
+
+    case GCC:
+      return false;
+    case GNUstep:
+      return getVersion() >= VersionTuple(1, 6);
+    case ObjFW:
+      return true;
     }
     llvm_unreachable("bad kind");
   }
@@ -273,23 +294,21 @@ class ObjCRuntime {
   /// Does this runtime supports optimized setter entrypoints?
   bool hasOptimizedSetter() const {
     switch (getKind()) {
-      case MacOSX:
-        return getVersion() >= VersionTuple(10, 8);
-      case iOS:
-        return (getVersion() >= VersionTuple(6));
-      case WatchOS:
-        return true;
-      case GNUstep:
-        return getVersion() >= VersionTuple(1, 7);
-      default:
-        return false;
+    case MacOSX:
+      return getVersion() >= VersionTuple(10, 8);
+    case iOS:
+      return (getVersion() >= VersionTuple(6));
+    case WatchOS:
+      return true;
+    case GNUstep:
+      return getVersion() >= VersionTuple(1, 7);
+    default:
+      return false;
     }
   }
 
   /// Does this runtime allow the use of __weak?
-  bool allowsWeak() const {
-    return hasNativeWeak();
-  }
+  bool allowsWeak() const { return hasNativeWeak(); }
 
   /// Does this runtime natively provide ARC-compliant 'weak'
   /// entrypoints?
@@ -304,25 +323,30 @@ class ObjCRuntime {
   /// This is really a property of the library, not the runtime.
   bool hasSubscripting() const {
     switch (getKind()) {
-    case FragileMacOSX: return false;
-    case MacOSX: return getVersion() >= VersionTuple(10, 11);
-    case iOS: return getVersion() >= VersionTuple(9);
-    case WatchOS: return true;
+    case FragileMacOSX:
+      return false;
+    case MacOSX:
+      return getVersion() >= VersionTuple(10, 11);
+    case iOS:
+      return getVersion() >= VersionTuple(9);
+    case WatchOS:
+      return true;
 
     // This is really a lie, because some implementations and versions
     // of the runtime do not support ARC.  Probably -fgnu-runtime
     // should imply a "maximal" runtime or something?
-    case GCC: return true;
-    case GNUstep: return true;
-    case ObjFW: return true;
+    case GCC:
+      return true;
+    case GNUstep:
+      return true;
+    case ObjFW:
+      return true;
     }
     llvm_unreachable("bad kind");
   }
 
   /// Does this runtime allow sizeof or alignof on object types?
-  bool allowsSizeofAlignof() const {
-    return isFragile();
-  }
+  bool allowsSizeofAlignof() const { return isFragile(); }
 
   /// Does this runtime allow pointer arithmetic on objects?
   ///
@@ -354,13 +378,20 @@ class ObjCRuntime {
   /// without it, abort() must be used in pure ObjC files.
   bool hasTerminate() const {
     switch (getKind()) {
-    case FragileMacOSX: return getVersion() >= VersionTuple(10, 8);
-    case MacOSX: return getVersion() >= VersionTuple(10, 8);
-    case iOS: return getVersion() >= VersionTuple(5);
-    case WatchOS: return true;
-    case GCC: return false;
-    case GNUstep: return false;
-    case ObjFW: return false;
+    case FragileMacOSX:
+      return getVersion() >= VersionTuple(10, 8);
+    case MacOSX:
+      return getVersion() >= VersionTuple(10, 8);
+    case iOS:
+      return getVersion() >= VersionTuple(5);
+    case WatchOS:
+      return true;
+    case GCC:
+      return false;
+    case GNUstep:
+      return false;
+    case ObjFW:
+      return false;
     }
     llvm_unreachable("bad kind");
   }
@@ -368,13 +399,20 @@ class ObjCRuntime {
   /// Does this runtime support weakly importing classes?
   bool hasWeakClassImport() const {
     switch (getKind()) {
-    case MacOSX: return true;
-    case iOS: return true;
-    case WatchOS: return true;
-    case FragileMacOSX: return false;
-    case GCC: return true;
-    case GNUstep: return true;
-    case ObjFW: return true;
+    case MacOSX:
+      return true;
+    case iOS:
+      return true;
+    case WatchOS:
+      return true;
+    case FragileMacOSX:
+      return false;
+    case GCC:
+      return true;
+    case GNUstep:
+      return true;
+    case ObjFW:
+      return true;
     }
     llvm_unreachable("bad kind");
   }
@@ -382,13 +420,20 @@ class ObjCRuntime {
   /// Does this runtime use zero-cost exceptions?
   bool hasUnwindExceptions() const {
     switch (getKind()) {
-    case MacOSX: return true;
-    case iOS: return true;
-    case WatchOS: return true;
-    case FragileMacOSX: return false;
-    case GCC: return true;
-    case GNUstep: return true;
-    case ObjFW: return true;
+    case MacOSX:
+      return true;
+    case iOS:
+      return true;
+    case WatchOS:
+      return true;
+    case FragileMacOSX:
+      return false;
+    case GCC:
+      return true;
+    case GNUstep:
+      return true;
+    case ObjFW:
+      return true;
     }
     llvm_unreachable("bad kind");
   }
@@ -402,7 +447,8 @@ class ObjCRuntime {
       return true;
     case GNUstep:
       return getVersion() >= VersionTuple(1, 7);
-    default: return false;
+    default:
+      return false;
     }
   }
 
@@ -457,13 +503,20 @@ class ObjCRuntime {
   /// Does this runtime supports direct dispatch
   bool allowsDirectDispatch() const {
     switch (getKind()) {
-    case FragileMacOSX: return false;
-    case MacOSX: return true;
-    case iOS: return true;
-    case WatchOS: return true;
-    case GCC: return false;
-    case GNUstep: return false;
-    case ObjFW: return false;
+    case FragileMacOSX:
+      return false;
+    case MacOSX:
+      return true;
+    case iOS:
+      return true;
+    case WatchOS:
+      return true;
+    case GCC:
+      return false;
+    case GNUstep:
+      return false;
+    case ObjFW:
+      return false;
     }
     llvm_unreachable("bad kind");
   }

>From 5d2ee5e34277d2338573202634c6b349453c2b31 Mon Sep 17 00:00:00 2001
From: hmelder <service at hugomelder.com>
Date: Tue, 2 Jan 2024 21:43:09 +0100
Subject: [PATCH 4/4] Clang driver dispatch-method test for gnustep runtime

---
 clang/test/Driver/gnustep-dispatch-method.m | 38 +++++++++++++++++++++
 1 file changed, 38 insertions(+)
 create mode 100644 clang/test/Driver/gnustep-dispatch-method.m

diff --git a/clang/test/Driver/gnustep-dispatch-method.m b/clang/test/Driver/gnustep-dispatch-method.m
new file mode 100644
index 00000000000000..7f20455b9c2265
--- /dev/null
+++ b/clang/test/Driver/gnustep-dispatch-method.m
@@ -0,0 +1,38 @@
+// DEFINE: %{triple} =
+// DEFINE: %{ver} = 1.6
+// DEFINE: %{prefix} = CHECK-MSGSEND
+// DEFINE: %{check} = %clang --target=%{triple} -fobjc-runtime=gnustep-%{ver} -### -c %s 2>&1 | FileCheck -check-prefix=%{prefix} %s
+
+// REDEFINE: %{ver} = 1.6
+// REDEFINE: %{triple} = i386-unknown-freebsd
+// RUN: %{check}
+// REDEFINE: %{triple} = x86_64-unknown-freebsd
+// RUN: %{check}
+// REDEFINE: %{triple} = arm-unknown-freebsd
+// RUN: %{check}
+// REDEFINE: %{prefix} = CHECK-MSGLOOKUP
+// REDEFINE: %{triple} = aarch64-unknown-freebsd
+// RUN: %{check}
+// REDEFINE: %{triple} = mips64-unknown-freebsd
+// RUN: %{check}
+// REDEFINE: %{triple} = riscv64-unknown-freebsd
+// RUN: %{check}
+
+// REDEFINE: %{ver} = 1.9
+// REDEFINE: %{prefix} = CHECK-MSGSEND
+// REDEFINE: %{triple} = aarch64-unknown-freebsd
+// RUN: %{check}
+// REDEFINE: %{triple} = mips64-unknown-freebsd
+// RUN: %{check}
+// REDEFINE: %{prefix} = CHECK-MSGLOOKUP
+// REDEFINE: %{triple} = riscv64-unknown-freebsd
+// RUN: %{check}
+
+// REDEFINE: %{ver} = 2.2
+// REDEFINE: %{prefix} = CHECK-MSGSEND
+// REDEFINE: %{triple} = riscv64-unknown-freebsd
+// RUN: %{check}
+
+
+// CHECK-MSGSEND: "-cc1"{{.*}} "-fobjc-dispatch-method=non-legacy"
+// CHECK-MSGLOOKUP-NOT: "-cc1"{{.*}} "-fobjc-dispatch-method=non-legacy"
\ No newline at end of file



More information about the cfe-commits mailing list