Clang Project

clang_source_code/test/CodeGen/wasm-arguments.c
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)
10void f0(int i, long j, long long k, double l, long double m) {}
11
12typedef 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)
19void f1(s1 i) {}
20
21typedef 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()
27s2 f2(void) {
28  s2 foo;
29  return foo;
30}
31
32typedef 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)
39s3 f3(void) {
40  s3 foo;
41  return foo;
42}
43
44// WEBASSEMBLY32: define void @f4(i64 %i)
45// WEBASSEMBLY64: define void @f4(i64 %i)
46void 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)
51void 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)
55void f6(unsigned char a, unsigned short b) {}
56
57enum 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)
65void f7(enum my_enum a) {}
66
67enum 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)
73void f8(enum my_big_enum a) {}
74
75union 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)
82void f9(union simple_union s) {}
83
84typedef 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)
92void f10(bitfield1 bf1) {}
93