[clang] Allow direct dispatch for the ObjFW runtime (PR #126382)

Jonathan Schleifer via cfe-commits cfe-commits at lists.llvm.org
Tue Feb 25 13:09:41 PST 2025


================
@@ -2222,6 +2222,96 @@ class CGObjCObjFW: public CGObjCGNU {
     return ClassSymbol;
   }
 
+  void GenerateDirectMethodPrologue(
+      CodeGenFunction &CGF, llvm::Function *Fn, const ObjCMethodDecl *OMD,
+      const ObjCContainerDecl *CD) override {
+    auto &Builder = CGF.Builder;
+    bool ReceiverCanBeNull = true;
+    auto selfAddr = CGF.GetAddrOfLocalVar(OMD->getSelfDecl());
+    auto selfValue = Builder.CreateLoad(selfAddr);
+
+    // Generate:
+    //
+    // /* for class methods only to force class lazy initialization */
+    // self = [self self];
+    //
+    // /* unless the receiver is never NULL */
+    // if (self == nil) {
+    //     return (ReturnType){ };
+    // }
+    //
+    // _cmd = @selector(...)
+    // ...
+
+    if (OMD->isClassMethod()) {
+      const ObjCInterfaceDecl *OID = cast<ObjCInterfaceDecl>(CD);
+      assert(
+          OID &&
+          "GenerateDirectMethod() should be called with the Class Interface");
----------------
Midar wrote:

This is straight up copied from CGObjCMac, so I have no idea why it was done this way :)

https://github.com/llvm/llvm-project/pull/126382


More information about the cfe-commits mailing list