Skip to content

Commit 99ff671

Browse files
Merge pull request #69142 from kateinoigakukun/pr-5d6614268724c4057b9c6a18138a1e1d4c562443
2 parents 4f68365 + a0bb0d8 commit 99ff671

6 files changed

+14
-7
lines changed

include/swift/Basic/LangOptions.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ namespace swift {
177177
llvm::VersionTuple MinimumInliningTargetVersion;
178178

179179
/// The alternate name to use for the entry point instead of main.
180-
std::string entryPointFunctionName = "main";
180+
std::optional<std::string> entryPointFunctionName;
181181

182182
///
183183
/// Language features

lib/AST/ASTContext.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5906,7 +5906,14 @@ ASTContext::SILTransformCtors ASTContext::getIRGenSILTransforms() const {
59065906
}
59075907

59085908
std::string ASTContext::getEntryPointFunctionName() const {
5909-
return LangOpts.entryPointFunctionName;
5909+
// Set default entry point name
5910+
//
5911+
// Usually the main entrypoint is "main" but WebAssembly's C ABI uses
5912+
// "__main_argc_argv" for `int (int, char **)` signature and Swift's
5913+
// main entrypoint always takes argc/argv.
5914+
// See https://github.com/WebAssembly/tool-conventions/blob/main/BasicCABI.md
5915+
std::string defaultName = LangOpts.Target.isWasm() ? "__main_argc_argv" : "main";
5916+
return LangOpts.entryPointFunctionName.value_or(defaultName);
59105917
}
59115918

59125919
SILLayout *SILLayout::get(ASTContext &C,

test/IRGen/big_types_corner_cases.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class OptionalInoutFuncType {
3737
}
3838
}
3939

40-
// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} i32 @main(i32 %0, ptr %1)
40+
// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} i32 @{{main|__main_argc_argv}}(i32 %0, ptr %1)
4141
// CHECK: call void @llvm.lifetime.start
4242
// CHECK: call void @llvm.memcpy
4343
// CHECK: call void @llvm.lifetime.end

test/IRGen/default_function_ir_attributes.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ struct StructHoldingOutlined<T> {
3737
}
3838

3939
// main
40-
// CHECK-LABEL: define {{.*}} @main(
40+
// CHECK-LABEL: define {{.*}} @{{main|__main_argc_argv}}(
4141
// CHECK-SAME: [[ATTRS_SIMPLE:#[0-9]+]]
4242

4343
// class deinit

test/IRGen/opaque-pointer-llvm.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// RUN: %target-swift-frontend -Xcc -Xclang -Xcc -opaque-pointers -primary-file %s -emit-ir | %FileCheck %s --check-prefix=CHECK
22
// RUN: %target-swift-frontend -Xcc -Xclang -Xcc -no-opaque-pointers -primary-file %s -emit-ir | %FileCheck %s --check-prefix=CHECK-NO
33

4-
// CHECK: define{{.*}} @main({{.*}} %0, ptr %1)
5-
// CHECK-NO: define{{.*}} @main({{.*}} %0, i8** %1)
4+
// CHECK: define{{.*}} @{{main|__main_argc_argv}}({{.*}} %0, ptr %1)
5+
// CHECK-NO: define{{.*}} @{{main|__main_argc_argv}}({{.*}} %0, i8** %1)
66
public func test() {}

test/IRGen/wasm-absolute-func-ptr.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22

33
// REQUIRES: CODEGENERATOR=WebAssembly
44

5-
// CHECK: @"\01l_entry_point" = private constant { i32{{.*}} { i32 ptrtoint (ptr @main to i32){{.*}} }, section "swift5_entry", align 4
5+
// CHECK: @"\01l_entry_point" = private constant { i32{{.*}} { i32 ptrtoint (ptr @__main_argc_argv to i32){{.*}} }, section "swift5_entry", align 4
66

0 commit comments

Comments
 (0)