From fc46be997f8219e11900473c373b639525396064 Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Fri, 21 Jun 2013 00:20:25 +0000 Subject: [PATCH] When building a module, keep *all* declared methods in the global method pool. As an optimization, we only kept declared methods with distinct signatures in the global method pool, to keep the method lists small. Under modules, however, one could have two different methods with the same signature that occur in different (sub)modules. If only the later submodule is important, message sends to 'id' with that selector would fail because the first method (the only one that got into the method pool) was hidden. When building a module, keep *all* of the declared methods. I did a quick check of both module build time and uses of modules, and found no performance regression despite this causing us to keep more methods in the global method pool. Fixes . git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@184504 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaDeclObjC.cpp | 4 ++++ test/Modules/Inputs/MethodPoolBSub.h | 1 + test/Modules/Inputs/module.map | 4 ++++ test/Modules/method_pool.m | 4 ++++ 4 files changed, 13 insertions(+) diff --git a/lib/Sema/SemaDeclObjC.cpp b/lib/Sema/SemaDeclObjC.cpp index 526e479af0..618c9d99e1 100644 --- a/lib/Sema/SemaDeclObjC.cpp +++ b/lib/Sema/SemaDeclObjC.cpp @@ -2130,6 +2130,10 @@ void Sema::addMethodToGlobalList(ObjCMethodList *List, ObjCMethodDecl *Method) { // signature. ObjCMethodList *Previous = List; for (; List; Previous = List, List = List->getNext()) { + // If we are building a module, keep all of the methods. + if (getLangOpts().Modules && !getLangOpts().CurrentModule.empty()) + continue; + if (!MatchTwoMethodDeclarations(Method, List->Method)) continue; diff --git a/test/Modules/Inputs/MethodPoolBSub.h b/test/Modules/Inputs/MethodPoolBSub.h index 0a7899df81..fbfc0aa143 100644 --- a/test/Modules/Inputs/MethodPoolBSub.h +++ b/test/Modules/Inputs/MethodPoolBSub.h @@ -1,4 +1,5 @@ @interface B (Sub) - (char *)method3; - (char*)method4; +- (id)method6; @end diff --git a/test/Modules/Inputs/module.map b/test/Modules/Inputs/module.map index 249700a494..5a95ce9edc 100644 --- a/test/Modules/Inputs/module.map +++ b/test/Modules/Inputs/module.map @@ -131,6 +131,10 @@ module MethodPoolA { module MethodPoolB { header "MethodPoolB.h" + explicit module Sub2 { + header "MethodPoolBSub2.h" + } + explicit module Sub { header "MethodPoolBSub.h" } diff --git a/test/Modules/method_pool.m b/test/Modules/method_pool.m index 6fd74b0885..f7d5ae700c 100644 --- a/test/Modules/method_pool.m +++ b/test/Modules/method_pool.m @@ -47,6 +47,10 @@ void testMethod3Again(id object) { char *str = [object method3]; // okay: only found in MethodPoolB.Sub } +void testMethod6(id object) { + [object method6]; +} + @import MethodPoolA.Sub; void testMethod3AgainAgain(id object) { -- 2.40.0