File tree Expand file tree Collapse file tree 2 files changed +55
-0
lines changed
clang/test/CodeGenWebAssembly Expand file tree Collapse file tree 2 files changed +55
-0
lines changed Original file line number Diff line number Diff line change 1+ // REQUIRES: webassembly-registered-target
2+ // RUN: %clang_cc1 -triple wasm32-unknown-unknown -emit-llvm -O0 -o - %s | FileCheck %s
3+
4+ // Test of function pointer bitcast in a function argument with different argument number in 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+ 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
Original file line number Diff line number Diff line change 1+ // REQUIRES: webassembly-registered-target
2+ // RUN: %clang_cc1 -triple wasm32-unknown-unknown -emit-llvm -O0 -o - %s | FileCheck %s
3+
4+ // Test of function pointer bitcast in a struct field with different argument number in wasm32
5+
6+ #define FUNCTION_POINTER (f ) ((FunctionPointer)(f))
7+ typedef int (* FunctionPointer )(int a , int b );
8+
9+ // CHECK: @__const.test.sfp = private unnamed_addr constant %struct._StructWithFunctionPointer { ptr @__fp_less_iii }, align 4
10+
11+ typedef struct _StructWithFunctionPointer {
12+ FunctionPointer fp ;
13+ } StructWithFunctionPointer ;
14+
15+ int fp_less (int a ) {
16+ return a ;
17+ }
18+
19+ // CHECK-LABEL: @test
20+ void test () {
21+ StructWithFunctionPointer sfp = {
22+ FUNCTION_POINTER (fp_less )
23+ };
24+
25+ int a1 = sfp .fp (10 , 20 );
26+ }
27+
28+ // CHECK: define internal i32 @__fp_less_iii(i32 %0, i32 %1)
29+ // CHECK: %2 = call i32 @fp_less(i32 %0)
30+ // CHECK: ret i32 %2
You can’t perform that action at this time.
0 commit comments