Skip to content

Commit fd3e784

Browse files
committed
[interop] test, add tests that function pointers called from Swift trap on uncaught exceptions
1 parent 7dbfc51 commit fd3e784

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

test/Interop/Cxx/exceptions/trap-on-exception-irgen-itanium.swift

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,20 @@ public:
6767
using TestTemplateInt = TestTemplate<int>;
6868
using TestTemplateBool = TestTemplate<bool>;
6969

70+
using TestFunctionTy = int (* _Nonnull)(int);
71+
72+
inline TestFunctionTy getFreeFunctionThrowsPtr() noexcept {
73+
return &freeFunctionThrows;
74+
}
75+
76+
extern "C" {
77+
78+
typedef void ( * _Nonnull CFreeFunctionTy)(void);
79+
80+
CFreeFunctionTy getCFreeFunctionPointer() noexcept;
81+
82+
}
83+
7084
//--- test.swift
7185

7286
import CxxModule
@@ -105,10 +119,22 @@ func testTemplateCalls() {
105119
v2.dependentNoExceptMethod()
106120
}
107121

122+
func testFuncPtrCall() {
123+
let funcPtr = getFreeFunctionThrowsPtr()
124+
let _ = funcPtr(2)
125+
}
126+
127+
func testCFuncPtrCall() {
128+
let funcPtr = getCFreeFunctionPointer()
129+
funcPtr()
130+
}
131+
108132
let _ = testFreeFunctionNoThrowOnly()
109133
let _ = testFreeFunctionCalls()
110134
let _ = testMethodCalls()
111135
testTemplateCalls()
136+
testFuncPtrCall()
137+
testCFuncPtrCall()
112138

113139
// CHECK: define {{.*}} @"$s4test0A23FreeFunctionNoThrowOnlys5Int32VyF"() #[[#SWIFTMETA:]] {
114140
// CHECK-NEXT: :
@@ -182,6 +208,20 @@ testTemplateCalls()
182208
// CHECK: [[CONT12]]:
183209
// CHECK: ret
184210

211+
// CHECK: define {{.*}} @"$s4test0A11FuncPtrCallyyF"() #[[#SWIFTUWMETA]] personality
212+
// CHECK: call i32 (i32)* @_Z24getFreeFunctionThrowsPtrv()
213+
// CHECK: invoke i32 %{{.*}}(i32 2)
214+
// CHECK-NEXT: to label %[[CONT20:.*]] unwind label %{{.*}}
215+
// CHECK: [[CONT20]]:
216+
// CHECK-NEXT: ret void
217+
218+
// CHECK: define {{.*}} @"$s4test0A12CFuncPtrCallyyF"() #[[#SWIFTUWMETA]] personality
219+
// CHECK: call void ()* @getCFreeFunctionPointer()
220+
// CHECK: invoke void %{{.*}}()
221+
// CHECK-NEXT: to label %[[CONT21:.*]] unwind label %{{.*}}
222+
// CHECK: [[CONT21]]:
223+
// CHECK-NEXT: ret void
224+
185225
// CHECK: i32 @__gxx_personality_v0(...)
186226

187227
// CHECK: attributes #[[#SWIFTMETA]] = {

0 commit comments

Comments
 (0)