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: [[CAST_TMP:%.*]] = bitcast [[REC]]* [[RET]] to [[AGG:{ i32, \[2 x i8\], i8, \[1 x i8\], float, float }]]*
53 // CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 0
54 // CHECK: [[FIRST:%.*]] = load i32, i32* [[T0]], align 4
55 // CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 2
56 // CHECK: [[SECOND:%.*]] = load i8, i8* [[T0]], align 2
57 // CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 4
58 // CHECK: [[THIRD:%.*]] = load float, float* [[T0]], align 4
59 // CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 5
60 // CHECK: [[FOURTH:%.*]] = load float, float* [[T0]], align 4
61 // CHECK: [[T0:%.*]] = insertvalue [[UAGG:{ i32, i8, float, float }]] undef, i32 [[FIRST]], 0
62 // CHECK: [[T1:%.*]] = insertvalue [[UAGG]] [[T0]], i8 [[SECOND]], 1
63 // CHECK: [[T2:%.*]] = insertvalue [[UAGG]] [[T1]], float [[THIRD]], 2
64 // CHECK: [[T3:%.*]] = insertvalue [[UAGG]] [[T2]], float [[FOURTH]], 3
65 // CHECK: ret [[UAGG]] [[T3]]
66 // CHECK-LABEL: define {{.*}} @take_struct_1(i32 %0, i8 %1, float %2, float %3)
67 // CHECK: [[V:%.*]] = alloca [[REC]], align 4
68 // CHECK: [[CAST_TMP:%.*]] = bitcast [[REC]]* [[V]] to [[AGG]]*
69 // CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 0
70 // CHECK: store i32 %0, i32* [[T0]], align 4
71 // CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 2
72 // CHECK: store i8 %1, i8* [[T0]], align 2
73 // CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 4
74 // CHECK: store float %2, float* [[T0]], align 4
75 // CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 5
76 // CHECK: store float %3, float* [[T0]], align 4
78 // CHECK-LABEL: define{{.*}} void @test_struct_1()
79 // CHECK: [[TMP:%.*]] = alloca [[REC]], align 4
80 // CHECK: [[CALL:%.*]] = call [[SWIFTCC:swiftcc]] [[UAGG]] @return_struct_1()
81 // CHECK: [[CAST_TMP:%.*]] = bitcast [[REC]]* [[TMP]] to [[AGG]]*
82 // CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 0
83 // CHECK: [[T1:%.*]] = extractvalue [[UAGG]] [[CALL]], 0
84 // CHECK: store i32 [[T1]], i32* [[T0]], align 4
85 // CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 2
86 // CHECK: [[T1:%.*]] = extractvalue [[UAGG]] [[CALL]], 1
87 // CHECK: store i8 [[T1]], i8* [[T0]], align 2
88 // CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 4
89 // CHECK: [[T1:%.*]] = extractvalue [[UAGG]] [[CALL]], 2
90 // CHECK: store float [[T1]], float* [[T0]], align 4
91 // CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 5
92 // CHECK: [[T1:%.*]] = extractvalue [[UAGG]] [[CALL]], 3
93 // CHECK: store float [[T1]], float* [[T0]], align 4
94 // CHECK: [[CAST_TMP:%.*]] = bitcast [[REC]]* [[TMP]] to [[AGG]]*
95 // CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 0
96 // CHECK: [[FIRST:%.*]] = load i32, i32* [[T0]], align 4
97 // CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 2
98 // CHECK: [[SECOND:%.*]] = load i8, i8* [[T0]], align 2
99 // CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 4
100 // CHECK: [[THIRD:%.*]] = load float, float* [[T0]], align 4
101 // CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 5
102 // CHECK: [[FOURTH:%.*]] = load float, float* [[T0]], align 4
103 // CHECK: call [[SWIFTCC]] void @take_struct_1(i32 [[FIRST]], i8 [[SECOND]], float [[THIRD]], float [[FOURTH]])
106 struct struct_indirect_1
{
108 ~struct_indirect_1();
110 TEST(struct_indirect_1
)
112 // CHECK-LABEL: define {{.*}} void @return_struct_indirect_1({{.*}} noalias sret
114 // Should not be byval.
115 // CHECK-LABEL: define {{.*}} void @take_struct_indirect_1({{.*}}* noundef{{( %.*)?}})
117 // Do a simple standalone test here of a function definition to ensure that
118 // we don't have problems due to failure to eagerly synthesize a copy
119 // constructor declaration.
120 class struct_trivial
{
123 // CHECK-LABEL: define{{.*}} swiftcc void @test_struct_trivial(i32{{( %.*)?}})
125 void test_struct_trivial(struct_trivial triv
) {}