1 | // RUN: %clang_cc1 -triple wasm32-unknown-unknown %s -emit-llvm -o - \ |
2 | // RUN: | FileCheck %s -check-prefix=WEBASSEMBLY32 |
3 | // RUN: %clang_cc1 -triple wasm64-unknown-unknown %s -emit-llvm -o - \ |
4 | // RUN: | FileCheck %s -check-prefix=WEBASSEMBLY64 |
5 | |
6 | // Basic argument/attribute tests for WebAssembly |
7 | |
8 | // WEBASSEMBLY32: define void @f0(i32 %i, i32 %j, i64 %k, double %l, fp128 %m) |
9 | // WEBASSEMBLY64: define void @f0(i32 %i, i64 %j, i64 %k, double %l, fp128 %m) |
10 | void f0(int i, long j, long long k, double l, long double m) {} |
11 | |
12 | typedef struct { |
13 | int aa; |
14 | int bb; |
15 | } s1; |
16 | // Structs should be passed byval and not split up. |
17 | // WEBASSEMBLY32: define void @f1(%struct.s1* byval align 4 %i) |
18 | // WEBASSEMBLY64: define void @f1(%struct.s1* byval align 4 %i) |
19 | void f1(s1 i) {} |
20 | |
21 | typedef struct { |
22 | int cc; |
23 | } s2; |
24 | // Single-element structs should be returned as the one element. |
25 | // WEBASSEMBLY32: define i32 @f2() |
26 | // WEBASSEMBLY64: define i32 @f2() |
27 | s2 f2(void) { |
28 | s2 foo; |
29 | return foo; |
30 | } |
31 | |
32 | typedef struct { |
33 | int cc; |
34 | int dd; |
35 | } s3; |
36 | // Structs should be returned sret and not simplified by the frontend. |
37 | // WEBASSEMBLY32: define void @f3(%struct.s3* noalias sret %agg.result) |
38 | // WEBASSEMBLY64: define void @f3(%struct.s3* noalias sret %agg.result) |
39 | s3 f3(void) { |
40 | s3 foo; |
41 | return foo; |
42 | } |
43 | |
44 | // WEBASSEMBLY32: define void @f4(i64 %i) |
45 | // WEBASSEMBLY64: define void @f4(i64 %i) |
46 | void f4(long long i) {} |
47 | |
48 | // i8/i16 should be signext, i32 and higher should not. |
49 | // WEBASSEMBLY32: define void @f5(i8 signext %a, i16 signext %b) |
50 | // WEBASSEMBLY64: define void @f5(i8 signext %a, i16 signext %b) |
51 | void f5(char a, short b) {} |
52 | |
53 | // WEBASSEMBLY32: define void @f6(i8 zeroext %a, i16 zeroext %b) |
54 | // WEBASSEMBLY64: define void @f6(i8 zeroext %a, i16 zeroext %b) |
55 | void f6(unsigned char a, unsigned short b) {} |
56 | |
57 | enum my_enum { |
58 | ENUM1, |
59 | ENUM2, |
60 | ENUM3, |
61 | }; |
62 | // Enums should be treated as the underlying i32. |
63 | // WEBASSEMBLY32: define void @f7(i32 %a) |
64 | // WEBASSEMBLY64: define void @f7(i32 %a) |
65 | void f7(enum my_enum a) {} |
66 | |
67 | enum my_big_enum { |
68 | ENUM4 = 0xFFFFFFFFFFFFFFFF, |
69 | }; |
70 | // Big enums should be treated as the underlying i64. |
71 | // WEBASSEMBLY32: define void @f8(i64 %a) |
72 | // WEBASSEMBLY64: define void @f8(i64 %a) |
73 | void f8(enum my_big_enum a) {} |
74 | |
75 | union simple_union { |
76 | int a; |
77 | char b; |
78 | }; |
79 | // Unions should be passed as byval structs. |
80 | // WEBASSEMBLY32: define void @f9(%union.simple_union* byval align 4 %s) |
81 | // WEBASSEMBLY64: define void @f9(%union.simple_union* byval align 4 %s) |
82 | void f9(union simple_union s) {} |
83 | |
84 | typedef struct { |
85 | int b4 : 4; |
86 | int b3 : 3; |
87 | int b8 : 8; |
88 | } bitfield1; |
89 | // Bitfields should be passed as byval structs. |
90 | // WEBASSEMBLY32: define void @f10(%struct.bitfield1* byval align 4 %bf1) |
91 | // WEBASSEMBLY64: define void @f10(%struct.bitfield1* byval align 4 %bf1) |
92 | void f10(bitfield1 bf1) {} |
93 | |