1 ; RUN: opt -S -wasm-add-missing-prototypes %s | FileCheck %s
3 target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
4 target triple = "wasm32-unknown-unknown"
6 ; CHECK: @foo_addr = global i64 (i32)* @foo, align 8
7 @foo_addr = global i64 (i32)* bitcast (i64 (...)* @foo to i64 (i32)*), align 8
9 ; CHECK: @foo_addr_i8 = global i8* bitcast (i64 (i32)* @foo to i8*), align 8
10 @foo_addr_i8 = global i8* bitcast (i64 (...)* @foo to i8*), align 8
12 ; CHECK-LABEL: @call_foo
13 ; CHECK: %call = call i64 @foo(i32 42)
14 define void @call_foo(i32 %a) {
15 %call = call i64 bitcast (i64 (...)* @foo to i64 (i32)*)(i32 42)
19 ; CHECK-LABEL: @call_foo_ptr
20 ; CHECK: %1 = bitcast i64 (...)* bitcast (i64 (i32)* @foo to i64 (...)*) to i64 (i32)*
21 ; CHECK-NEXT: %call = call i64 %1(i32 43)
22 define i64 @call_foo_ptr(i32 %a) {
23 %1 = bitcast i64 (...)* @foo to i64 (i32)*
24 %call = call i64 (i32) %1(i32 43)
28 ; CHECK-LABEL: @to_intptr_inst
29 ; CHECK: %1 = bitcast i64 (...)* bitcast (i64 (i32)* @foo to i64 (...)*) to i8*
30 ; CHECK-NEXT: ret i8* %1
31 define i8* @to_intptr_inst() {
32 %1 = bitcast i64 (...)* @foo to i8*
36 ; CHECK-LABEL: @to_intptr_constexpr
37 ; CHECK: ret i8* bitcast (i64 (i32)* @foo to i8*)
38 define i8* @to_intptr_constexpr() {
39 ret i8* bitcast (i64 (...)* @foo to i8*)
42 ; CHECK-LABEL: @null_compare
43 ; CHECK: br i1 icmp eq (i64 (...)* bitcast (i64 (i32)* @foo to i64 (...)*), i64 (...)* null), label %if.then, label %if.end
44 define i8 @null_compare() {
45 br i1 icmp eq (i64 (...)* @foo, i64 (...)* null), label %if.then, label %if.end
52 ; CHECK-LABEL: @as_paramater
53 ; CHECK: call void @func_param(i64 (...)* bitcast (i64 (i32)* @foo to i64 (...)*))
54 define void @as_paramater() {
55 call void @func_param(i64 (...)* @foo)
59 ; Check if a sret parameter works in a no-prototype function.
60 ; CHECK-LABEL: @sret_param
61 ; CHECK: call void @make_struct_foo(%struct.foo* sret %foo)
62 %struct.foo = type { i32, i32 }
63 declare void @make_struct_foo(%struct.foo* sret, ...) #1
64 define void @sret_param() {
65 %foo = alloca %struct.foo, align 4
66 call void bitcast (void (%struct.foo*, ...)* @make_struct_foo to void (%struct.foo*)*)(%struct.foo* sret %foo)
70 declare void @func_param(i64 (...)*)
72 ; CHECK: declare void @func_not_called()
73 declare void @func_not_called(...) #1
75 ; CHECK: declare extern_weak i64 @foo(i32)
76 declare extern_weak i64 @foo(...) #1
78 ; CHECK-NOT: attributes {{.*}} = { {{.*}}"no-prototype"{{.*}} }
79 attributes #1 = { "no-prototype" }