Skip to content

Commit b51657b

Browse files
committed
[wasm] Add function pointer think tests
1 parent fb25f38 commit b51657b

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// REQUIRES: webassembly-registered-target
2+
// RUN: %clang_cc1 -triple wasm32-unknown-unknown -emit-llvm -O1 -o - %s | FileCheck %s
3+
4+
// Basic test of function pointer usage for wasm32
5+
6+
#define FUNCTION_POINTER(f) ((FunctionPointer)(f))
7+
typedef int (*FunctionPointer)(int a, int b);
8+
9+
int fp_as_arg(FunctionPointer fp, int a, int b) {
10+
return fp(a, b);
11+
}
12+
13+
int fp_less(int a) {
14+
return a;
15+
}
16+
17+
// CHECK-LABEL: @test
18+
// CHECK: call i32 @fp_as_arg(ptr noundef @__fp_less_iii, i32 noundef 10, i32 noundef 20)
19+
void test() {
20+
return fp_as_arg(FUNCTION_POINTER(fp_less), 10, 20);
21+
}
22+
23+
// CHECK: define internal i32 @__fp_less_iii(i32 %0, i32 %1)
24+
// CHECK: %2 = call i32 @fp_less(i32 %0)
25+
// CHECK: ret i32 %2

0 commit comments

Comments
 (0)