SILGen: Cope with overloads when emitting artificial main for @UIApplicationMain.

The overlay may add overloads for UIApplicationMain for various reasons. When we generate the special `main` implementation for a `@UIApplicationMain` class, we want to call the original function from Objective-C, so pick that one where there are multiple overloads to choose from. Fixes rdar://problem/42352695.
This commit is contained in:
Joe Groff
2018-07-18 15:58:11 -07:00
parent f83c17ca7f
commit cba32f79a5
5 changed files with 31 additions and 2 deletions

View File

@@ -449,9 +449,24 @@ void SILGenFunction::emitArtificialTopLevel(ClassDecl *mainClass) {
/*resolver*/nullptr,
results);
assert(!results.empty() && "couldn't find UIApplicationMain in UIKit");
assert(results.size() == 1 && "more than one UIApplicationMain?");
auto mainRef = SILDeclRef(results.front()).asForeign();
// We want the original UIApplicationMain() declaration from Objective-C,
// not any overlay overloads.
ValueDecl *UIApplicationMainDecl = nullptr;
for (auto *result : results) {
if (result->hasClangNode()) {
assert(!UIApplicationMainDecl
&& "more than one UIApplicationMain defined in ObjC?!");
UIApplicationMainDecl = result;
#ifndef NDEBUG
break;
#endif
}
}
assert(UIApplicationMainDecl && "no UIApplicationMain defined in ObjC?!");
auto mainRef = SILDeclRef(UIApplicationMainDecl).asForeign();
auto UIApplicationMainFn = SGM.M.getOrCreateFunction(mainClass, mainRef,
NotForDefinition);
auto fnTy = UIApplicationMainFn->getLoweredFunctionType();