[lld] [lld-macho][ObjC] Implement category merging into base class (PR #92448)

Ellis Hoag via llvm-commits llvm-commits at lists.llvm.org
Thu May 16 14:09:53 PDT 2024


================
@@ -1265,10 +1297,16 @@ void ObjcCategoryMerger::removeRefsToErasedIsecs() {
 void ObjcCategoryMerger::doMerge() {
   collectAndValidateCategoriesData();
 
-  for (auto &entry : categoryMap)
-    if (entry.second.size() > 1)
+  for (auto &entry : categoryMap) {
+    if (isa<Defined>(entry.first)) {
+      // Merge all categories into the base class
+      auto *baseClass = cast<Defined>(entry.first);
+      mergeCategoriesIntoBaseClass(baseClass, entry.second);
+    } else if (entry.second.size() > 1) {
----------------
ellishg wrote:

Also, I'm not sure if you can do `for (auto &[sym, cats]: categoryMap)`, but that would be nice.

```suggestion
  for (auto &entry : categoryMap) {
    if (auto *baseClass = dyn_cast<Defined>(entry.first)) {
      // Merge all categories into the base class
      mergeCategoriesIntoBaseClass(baseClass, entry.second);
    } else if (entry.second.size() > 1) {
```

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


More information about the llvm-commits mailing list