mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
In WebAssembly, `main` function is mangled differently depending on if it takes argc/argv or not. If it doesn't take them, it's mangled to `main` as well as other platforms, so remove unused argc/argv in executable tests to avoid linkage failure.
95 lines
5.3 KiB
Plaintext
95 lines
5.3 KiB
Plaintext
// RUN: %empty-directory(%t)
|
|
// RUN: %target-build-swift-dylib(%t/%target-library-name(PrintShims)) %S/../../Inputs/print-shims.swift -module-name PrintShims -emit-module -emit-module-path %t/PrintShims.swiftmodule
|
|
// RUN: %target-codesign %t/%target-library-name(PrintShims)
|
|
// RUN: %target-build-swift -g -parse-sil %s -emit-ir -I %t -L %t -lPrintShim | %FileCheck %s --check-prefix=CHECK-LL
|
|
// RUN: %target-build-swift -g -parse-sil %s -module-name main -o %t/main -I %t -L %t -lPrintShims %target-rpath(%t)
|
|
// RUN: %target-codesign %t/main
|
|
// RUN: %target-run %t/main %t/%target-library-name(PrintShims) | %FileCheck %s
|
|
|
|
// REQUIRES: executable_test
|
|
// REQUIRES: swift_test_mode_optimize_none
|
|
// REQUIRES: concurrency
|
|
// REQUIRES: concurrency_runtime
|
|
// UNSUPPORTED: back_deployment_runtime
|
|
|
|
import Builtin
|
|
import Swift
|
|
import PrintShims
|
|
import _Concurrency
|
|
|
|
sil public_external @printGeneric : $@convention(thin) <T> (@in_guaranteed T) -> ()
|
|
sil public_external @printInt64 : $@convention(thin) (Int64) -> ()
|
|
|
|
sil hidden @createAndInvokeClosure : $@async @convention(thin) () -> () {
|
|
bb0:
|
|
%captured_literal = integer_literal $Builtin.Int64, 783247897
|
|
%captured = struct $Int64 (%captured_literal : $Builtin.Int64)
|
|
%createPartialApply = function_ref @createPartialApply : $@async @convention(thin) (Int64) -> @owned @async @callee_guaranteed (Int64) -> Int64
|
|
%partialApply = apply %createPartialApply(%captured) : $@async @convention(thin) (Int64) -> @owned @async @callee_guaranteed (Int64) -> Int64
|
|
strong_retain %partialApply : $@async @callee_guaranteed (Int64) -> Int64
|
|
%applied_literal = integer_literal $Builtin.Int64, 7823478
|
|
%applied = struct $Int64 (%applied_literal : $Builtin.Int64)
|
|
%sum = apply %partialApply(%applied) : $@async @callee_guaranteed (Int64) -> Int64
|
|
strong_release %partialApply : $@async @callee_guaranteed (Int64) -> Int64
|
|
%printInt64 = function_ref @printInt64 : $@convention(thin) (Int64) -> ()
|
|
%result = apply %printInt64(%sum) : $@convention(thin) (Int64) -> () // CHECK: 791071375
|
|
strong_release %partialApply : $@async @callee_guaranteed (Int64) -> Int64
|
|
return %result : $()
|
|
}
|
|
|
|
// CHECK-LL: @closureTu =
|
|
// CHECK-LL: define internal swift{{(tail)?}}cc void @closure(
|
|
// CHECK-LL: define internal swift{{(tail)?}}cc void @"$s7closureTA"(
|
|
sil hidden @createPartialApply : $@async @convention(thin) (Int64) -> @owned @async @callee_guaranteed (Int64) -> Int64 {
|
|
bb0(%captured : $Int64):
|
|
%closure = function_ref @closure : $@async @convention(thin) (Int64, Int64) -> Int64
|
|
%partialApply = partial_apply [callee_guaranteed] %closure(%captured) : $@async @convention(thin) (Int64, Int64) -> Int64
|
|
return %partialApply : $@async @callee_guaranteed (Int64) -> Int64
|
|
}
|
|
|
|
sil private @closure : $@async @convention(thin) (Int64, Int64) -> Int64 {
|
|
bb0(%one : $Int64, %two : $Int64):
|
|
%printInt64 = function_ref @printInt64 : $@convention(thin) (Int64) -> ()
|
|
%printInt64_1 = apply %printInt64(%one) : $@convention(thin) (Int64) -> ()
|
|
%printInt64_2 = apply %printInt64(%two) : $@convention(thin) (Int64) -> ()
|
|
%one_builtin = struct_extract %one : $Int64, #Int64._value
|
|
%two_builtin = struct_extract %two : $Int64, #Int64._value
|
|
%flag = integer_literal $Builtin.Int1, -1
|
|
%sumAndOverflowed = builtin "sadd_with_overflow_Int64"(%one_builtin : $Builtin.Int64, %two_builtin : $Builtin.Int64, %flag : $Builtin.Int1) : $(Builtin.Int64, Builtin.Int1)
|
|
%sum_builtin = tuple_extract %sumAndOverflowed : $(Builtin.Int64, Builtin.Int1), 0
|
|
%overflowed = tuple_extract %sumAndOverflowed : $(Builtin.Int64, Builtin.Int1), 1
|
|
cond_fail %overflowed : $Builtin.Int1, "arithmetic overflow"
|
|
%sum = struct $Int64 (%sum_builtin : $Builtin.Int64)
|
|
return %sum : $Int64
|
|
}
|
|
|
|
sil @test_case : $@convention(thin) @async () -> () {
|
|
%createAndInvokeClosure = function_ref @createAndInvokeClosure : $@async @convention(thin) () -> ()
|
|
%createAndInvokeClosure_result = apply %createAndInvokeClosure() : $@async @convention(thin) () -> ()
|
|
|
|
%void = tuple()
|
|
return %void : $()
|
|
}
|
|
|
|
// Defined in _Concurrency
|
|
sil @$ss13_runAsyncMainyyyyYaKcF : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> ()
|
|
|
|
sil @no_throw_to_throw_think : $@convention(thin) @async (@guaranteed @async @callee_guaranteed () -> ()) -> @error Error {
|
|
bb0(%0 :$@async @callee_guaranteed () -> ()):
|
|
%void = apply %0() : $@async @callee_guaranteed () -> ()
|
|
return %void : $()
|
|
}
|
|
|
|
// main
|
|
sil @main : $@convention(c) () -> Int32 {
|
|
%test_case_nothrow = function_ref @test_case : $@convention(thin) @async () -> ()
|
|
%thick_test_case = thin_to_thick_function %test_case_nothrow : $@convention(thin) @async () -> () to $@callee_guaranteed @async () -> ()
|
|
%thunk = function_ref @no_throw_to_throw_think : $@convention(thin) @async (@guaranteed @async @callee_guaranteed () -> ()) -> @error Error
|
|
%throwing = partial_apply [callee_guaranteed] %thunk(%thick_test_case) : $@convention(thin) @async (@guaranteed @async @callee_guaranteed () -> ()) -> @error Error
|
|
%runAsyncMain = function_ref @$ss13_runAsyncMainyyyyYaKcF : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> ()
|
|
%result = apply %runAsyncMain(%throwing) : $@convention(thin) (@guaranteed @async @callee_guaranteed () -> @error Error) -> ()
|
|
%out_literal = integer_literal $Builtin.Int32, 0
|
|
%out = struct $Int32 (%out_literal : $Builtin.Int32)
|
|
return %out : $Int32
|
|
}
|