1 // RUN: %clang_cc1 -triple armv7-apple-darwin9 -emit-llvm -o - %s -Wno-return-type-c-linkage -std=c++03 | FileCheck %s -check-prefixes=CHECK
3 // This isn't really testing anything ARM-specific; it's just a convenient
6 #define SWIFTCALL __attribute__((swiftcall))
7 #define OUT __attribute__((swift_indirect_result))
8 #define ERROR __attribute__((swift_error_result))
9 #define CONTEXT __attribute__((swift_context))
11 /*****************************************************************************/
12 /********************************** LOWERING *********************************/
13 /*****************************************************************************/
16 extern "C" SWIFTCALL TYPE return_##TYPE(void) { \
20 extern "C" SWIFTCALL void take_##TYPE(TYPE v) { \
22 extern "C" void test_##TYPE() { \
23 take_##TYPE(return_##TYPE()); \
26 /*****************************************************************************/
27 /*********************************** STRUCTS *********************************/
28 /*****************************************************************************/
33 // CHECK-LABEL: define {{.*}} @return_struct_empty()
35 // CHECK-LABEL: define {{.*}} @take_struct_empty()
38 // This is only properly testable in C++ because it relies on empty structs
39 // actually taking up space in a structure without requiring any extra data
43 struct_empty padding
[2];
49 // CHECK-LABEL: define {{.*}} @return_struct_1()
50 // CHECK: [[RET:%.*]] = alloca [[REC:%.*]], align 4
51 // CHECK: @llvm.memset
52 // CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG:{ i32, \[2 x i8\], i8, \[1 x i8\], float, float }]], ptr [[RET]], i32 0, i32 0
53 // CHECK: [[FIRST:%.*]] = load i32, ptr [[T0]], align 4
54 // CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], ptr [[RET]], i32 0, i32 2
55 // CHECK: [[SECOND:%.*]] = load i8, ptr [[T0]], align 2
56 // CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], ptr [[RET]], i32 0, i32 4
57 // CHECK: [[THIRD:%.*]] = load float, ptr [[T0]], align 4
58 // CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], ptr [[RET]], i32 0, i32 5
59 // CHECK: [[FOURTH:%.*]] = load float, ptr [[T0]], align 4
60 // CHECK: [[T0:%.*]] = insertvalue [[UAGG:{ i32, i8, float, float }]] poison, i32 [[FIRST]], 0
61 // CHECK: [[T1:%.*]] = insertvalue [[UAGG]] [[T0]], i8 [[SECOND]], 1
62 // CHECK: [[T2:%.*]] = insertvalue [[UAGG]] [[T1]], float [[THIRD]], 2
63 // CHECK: [[T3:%.*]] = insertvalue [[UAGG]] [[T2]], float [[FOURTH]], 3
64 // CHECK: ret [[UAGG]] [[T3]]
65 // CHECK-LABEL: define {{.*}} @take_struct_1(i32 %0, i8 %1, float %2, float %3)
66 // CHECK: [[V:%.*]] = alloca [[REC]], align 4
67 // CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], ptr [[V]], i32 0, i32 0
68 // CHECK: store i32 %0, ptr [[T0]], align 4
69 // CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], ptr [[V]], i32 0, i32 2
70 // CHECK: store i8 %1, ptr [[T0]], align 2
71 // CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], ptr [[V]], i32 0, i32 4
72 // CHECK: store float %2, ptr [[T0]], align 4
73 // CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], ptr [[V]], i32 0, i32 5
74 // CHECK: store float %3, ptr [[T0]], align 4
76 // CHECK-LABEL: define{{.*}} void @test_struct_1()
77 // CHECK: [[TMP:%.*]] = alloca [[REC]], align 4
78 // CHECK: [[CALL:%.*]] = call [[SWIFTCC:swiftcc]] [[UAGG]] @return_struct_1()
79 // CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], ptr [[TMP]], i32 0, i32 0
80 // CHECK: [[T1:%.*]] = extractvalue [[UAGG]] [[CALL]], 0
81 // CHECK: store i32 [[T1]], ptr [[T0]], align 4
82 // CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], ptr [[TMP]], i32 0, i32 2
83 // CHECK: [[T1:%.*]] = extractvalue [[UAGG]] [[CALL]], 1
84 // CHECK: store i8 [[T1]], ptr [[T0]], align 2
85 // CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], ptr [[TMP]], i32 0, i32 4
86 // CHECK: [[T1:%.*]] = extractvalue [[UAGG]] [[CALL]], 2
87 // CHECK: store float [[T1]], ptr [[T0]], align 4
88 // CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], ptr [[TMP]], i32 0, i32 5
89 // CHECK: [[T1:%.*]] = extractvalue [[UAGG]] [[CALL]], 3
90 // CHECK: store float [[T1]], ptr [[T0]], align 4
91 // CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], ptr [[TMP]], i32 0, i32 0
92 // CHECK: [[FIRST:%.*]] = load i32, ptr [[T0]], align 4
93 // CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], ptr [[TMP]], i32 0, i32 2
94 // CHECK: [[SECOND:%.*]] = load i8, ptr [[T0]], align 2
95 // CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], ptr [[TMP]], i32 0, i32 4
96 // CHECK: [[THIRD:%.*]] = load float, ptr [[T0]], align 4
97 // CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], ptr [[TMP]], i32 0, i32 5
98 // CHECK: [[FOURTH:%.*]] = load float, ptr [[T0]], align 4
99 // CHECK: call [[SWIFTCC]] void @take_struct_1(i32 [[FIRST]], i8 [[SECOND]], float [[THIRD]], float [[FOURTH]])
102 struct struct_indirect_1
{
104 ~struct_indirect_1();
106 TEST(struct_indirect_1
)
108 // CHECK-LABEL: define {{.*}} void @return_struct_indirect_1({{.*}} noalias sret
110 // Should not be byval.
111 // CHECK-LABEL: define {{.*}} void @take_struct_indirect_1(ptr noundef{{( %.*)?}})
113 // Do a simple standalone test here of a function definition to ensure that
114 // we don't have problems due to failure to eagerly synthesize a copy
115 // constructor declaration.
116 class struct_trivial
{
119 // CHECK-LABEL: define{{.*}} swiftcc void @test_struct_trivial(i32{{( %.*)?}})
121 void test_struct_trivial(struct_trivial triv
) {}