Skip to content

[4.2] SILGen: Cope with overloads when emitting artificial main for @UIApplicationMain. #18056

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions lib/SILGen/SILGenFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -446,9 +446,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();
Expand Down
1 change: 1 addition & 0 deletions test/SILGen/Inputs/UIKit.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import Foundation
@_exported import UIKit

public func UIApplicationMain() {}
6 changes: 6 additions & 0 deletions test/SILGen/Inputs/usr/include/UIKit.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
@protocol UIApplicationDelegate
@end

#ifdef SILGEN_TEST_UIAPPLICATIONMAIN_NULLABILITY
int UIApplicationMain(int argc, char *_Nullable *_Nonnull argv,
NSString *_Nullable principalClassName,
NSString *_Nullable delegateClassName);
#else
int UIApplicationMain(int argc, char **argv,
NSString *principalClassName,
NSString *delegateClassName);
#endif
4 changes: 4 additions & 0 deletions test/SILGen/UIApplicationMain.swift
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
// RUN: %empty-directory(%t)
// RUN: %build-silgen-test-overlays
// RUN: %build-silgen-test-overlays-ios

// RUN: %target-swift-frontend(mock-sdk: -sdk %S/Inputs -I %t) -emit-silgen -parse-as-library %s | %FileCheck %s
// RUN: %target-swift-frontend(mock-sdk: -sdk %S/Inputs -I %t) -emit-ir -parse-as-library %s | %FileCheck %s -check-prefix=IR

// RUN: %target-swift-frontend(mock-sdk: -DSILGEN_TEST_UIAPPLICATIONMAIN_NULLABILITY -sdk %S/Inputs -I %t) -emit-silgen -parse-as-library %s | %FileCheck %s
// RUN: %target-swift-frontend(mock-sdk: -DSILGEN_TEST_UIAPPLICATIONMAIN_NULLABILITY -sdk %S/Inputs -I %t) -emit-ir -parse-as-library %s | %FileCheck %s -check-prefix=IR

// RUN: %target-swift-frontend(mock-sdk: -sdk %S/Inputs -I %t) -emit-silgen -parse-as-library %s -D REFERENCE | %FileCheck %s
// RUN: %target-swift-frontend(mock-sdk: -sdk %S/Inputs -I %t) -emit-ir -parse-as-library %s -D REFERENCE | %FileCheck %s -check-prefix=IR

Expand Down
3 changes: 3 additions & 0 deletions test/SILGen/lit.local.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ config.substitutions.insert(0, ('%build-silgen-test-overlays',
'%target-swift-frontend(mock-sdk: -sdk %S/Inputs -I %t) -emit-module -o %t %S/Inputs/ObjectiveC.swift && '
'%target-swift-frontend(mock-sdk: -sdk %S/Inputs -I %t) -emit-module -o %t %S/Inputs/Dispatch.swift && '
'%target-swift-frontend(mock-sdk: -sdk %S/Inputs -I %t) -emit-module -o %t %S/Inputs/Foundation.swift'))

config.substitutions.insert(0, ('%build-silgen-test-overlays-ios',
'%target-swift-frontend(mock-sdk: -sdk %S/Inputs -I %t) -emit-module -o %t %S/Inputs/UIKit.swift'))