1 // RUN: %clang_cc1 -O1 -triple wasm32-unknown-unknown -emit-llvm -o - %s \
2 // RUN:   | FileCheck %s
3 // RUN: %clang_cc1 -O1 -triple wasm64-unknown-unknown -emit-llvm -o - %s \
4 // RUN:   | FileCheck %s
5 
6 #define concat_(x, y) x ## y
7 #define concat(x, y) concat_(x, y)
8 
9 #define test(T) \
10   T forward(T x) { return x; } \
11   void use(T x); \
12   T concat(def_, T)(void); \
13   void concat(test_, T)(void) { use(concat(def_, T)()); }
14 
15 struct one_field { double d; };
16 test(one_field);
17 // CHECK: define double @_Z7forward9one_field(double %{{.*}})
18 //
19 // CHECK: define void @_Z14test_one_fieldv()
20 // CHECK: %[[call:.*]] = tail call double @_Z13def_one_fieldv()
21 // CHECK: tail call void @_Z3use9one_field(double %[[call]])
22 // CHECK: ret void
23 //
24 // CHECK: declare void @_Z3use9one_field(double)
25 // CHECK: declare double @_Z13def_one_fieldv()
26 
27 struct two_fields { double d, e; };
28 test(two_fields);
29 // CHECK: define void @_Z7forward10two_fields(%struct.two_fields* noalias nocapture sret %{{.*}}, %struct.two_fields* byval nocapture readonly align 8 %{{.*}})
30 //
31 // CHECK: define void @_Z15test_two_fieldsv()
32 // CHECK: %[[tmp:.*]] = alloca %struct.two_fields, align 8
33 // CHECK: call void @_Z14def_two_fieldsv(%struct.two_fields* nonnull sret %[[tmp]])
34 // CHECK: call void @_Z3use10two_fields(%struct.two_fields* byval nonnull align 8 %[[tmp]])
35 // CHECK: ret void
36 //
37 // CHECK: declare void @_Z3use10two_fields(%struct.two_fields* byval align 8)
38 // CHECK: declare void @_Z14def_two_fieldsv(%struct.two_fields* sret)
39 
40 struct copy_ctor {
41     double d;
42     copy_ctor(copy_ctor const&);
43 };
44 test(copy_ctor);
45 // CHECK: define void @_Z7forward9copy_ctor(%struct.copy_ctor* noalias sret %{{.*}}, %struct.copy_ctor* %{{.*}})
46 //
47 // CHECK: declare %struct.copy_ctor* @_ZN9copy_ctorC1ERKS_(%struct.copy_ctor* returned, %struct.copy_ctor* dereferenceable(8))
48 //
49 // CHECK: define void @_Z14test_copy_ctorv()
50 // CHECK: %[[tmp:.*]] = alloca %struct.copy_ctor, align 8
51 // CHECK: call void @_Z13def_copy_ctorv(%struct.copy_ctor* nonnull sret %[[tmp]])
52 // CHECK: call void @_Z3use9copy_ctor(%struct.copy_ctor* nonnull %[[tmp]])
53 // CHECK: ret void
54 //
55 // CHECK: declare void @_Z3use9copy_ctor(%struct.copy_ctor*)
56 // CHECK: declare void @_Z13def_copy_ctorv(%struct.copy_ctor* sret)
57 
58 struct __attribute__((aligned(16))) aligned_copy_ctor {
59     double d, e;
60     aligned_copy_ctor(aligned_copy_ctor const&);
61 };
62 test(aligned_copy_ctor);
63 // CHECK: define void @_Z7forward17aligned_copy_ctor(%struct.aligned_copy_ctor* noalias sret %{{.*}}, %struct.aligned_copy_ctor* %{{.*}})
64 //
65 // CHECK: declare %struct.aligned_copy_ctor* @_ZN17aligned_copy_ctorC1ERKS_(%struct.aligned_copy_ctor* returned, %struct.aligned_copy_ctor* dereferenceable(16))
66 //
67 // CHECK: define void @_Z22test_aligned_copy_ctorv()
68 // CHECK: %[[tmp:.*]] = alloca %struct.aligned_copy_ctor, align 16
69 // CHECK: call void @_Z21def_aligned_copy_ctorv(%struct.aligned_copy_ctor* nonnull sret %[[tmp]])
70 // CHECK: call void @_Z3use17aligned_copy_ctor(%struct.aligned_copy_ctor* nonnull %[[tmp]])
71 // CHECK: ret void
72 //
73 // CHECK: declare void @_Z3use17aligned_copy_ctor(%struct.aligned_copy_ctor*)
74 // CHECK: declare void @_Z21def_aligned_copy_ctorv(%struct.aligned_copy_ctor* sret)
75 
76 struct empty {};
77 test(empty);
78 // CHECK: define void @_Z7forward5empty()
79 //
80 // CHECK: define void @_Z10test_emptyv()
81 // CHECK: tail call void @_Z9def_emptyv()
82 // CHECK: tail call void @_Z3use5empty()
83 // CHECK: ret void
84 //
85 // CHECK: declare void @_Z3use5empty()
86 // CHECK: declare void @_Z9def_emptyv()
87 
88 struct one_bitfield {
89     int d:3;
90 };
91 test(one_bitfield);
92 // CHECK: define i32 @_Z7forward12one_bitfield(i32 %{{.*}})
93 //
94 // CHECK: define void @_Z17test_one_bitfieldv()
95 // CHECK: %[[call:.*]] = tail call i32 @_Z16def_one_bitfieldv()
96 // CHECK: tail call void @_Z3use12one_bitfield(i32 %[[call]])
97 // CHECK: ret void
98 //
99 // CHECK: declare void @_Z3use12one_bitfield(i32)
100 // CHECK: declare i32 @_Z16def_one_bitfieldv()
101