xref: /llvm-project/clang/test/CodeGenCXX/arm-swiftcall.cpp (revision 94473f4db6a6f5f12d7c4081455b5b596094eac5)
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
2 
3 // For now just check that the RISC-V triples are accepted, but don't check the IR, as swiftcall is not yet supported.
4 // RUN: %clang_cc1 -triple riscv32-unknown-linux-gnu -emit-llvm -o - %s -Wno-return-type-c-linkage -std=c++03
5 // RUN: %clang_cc1 -triple riscv64-unknown-linux-gnu -emit-llvm -o - %s -Wno-return-type-c-linkage -std=c++03
6 
7 // This isn't really testing anything ARM-specific; it's just a convenient
8 // 32-bit platform.
9 
10 #define SWIFTCALL __attribute__((swiftcall))
11 #define OUT __attribute__((swift_indirect_result))
12 #define ERROR __attribute__((swift_error_result))
13 #define CONTEXT __attribute__((swift_context))
14 
15 /*****************************************************************************/
16 /********************************** LOWERING *********************************/
17 /*****************************************************************************/
18 
19 #define TEST(TYPE)                                  \
20   extern "C" SWIFTCALL TYPE return_##TYPE(void) {   \
21     TYPE result = {};                               \
22     return result;                                  \
23   }                                                 \
24   extern "C" SWIFTCALL void take_##TYPE(TYPE v) {   \
25   }                                                 \
26   extern "C" void test_##TYPE() {                   \
27     take_##TYPE(return_##TYPE());                   \
28   }
29 
30 /*****************************************************************************/
31 /*********************************** STRUCTS *********************************/
32 /*****************************************************************************/
33 
34 typedef struct {
35 } struct_empty;
36 TEST(struct_empty);
37 // CHECK-LABEL: define {{.*}} @return_struct_empty()
38 // CHECK:   ret void
39 // CHECK-LABEL: define {{.*}} @take_struct_empty()
40 // CHECK:   ret void
41 
42 // This is only properly testable in C++ because it relies on empty structs
43 // actually taking up space in a structure without requiring any extra data
44 // to be passed.
45 typedef struct {
46   int x;
47   struct_empty padding[2];
48   char c1;
49   float f0;
50   float f1;
51 } struct_1;
52 TEST(struct_1);
53 // CHECK-LABEL: define {{.*}} @return_struct_1()
54 // CHECK:   [[RET:%.*]] = alloca [[REC:%.*]], align 4
55 // CHECK:   @llvm.memset
56 // CHECK:   [[T0:%.*]] = getelementptr inbounds nuw [[AGG:{ i32, \[2 x i8\], i8, \[1 x i8\], float, float }]], ptr [[RET]], i32 0, i32 0
57 // CHECK:   [[FIRST:%.*]] = load i32, ptr [[T0]], align 4
58 // CHECK:   [[T0:%.*]] = getelementptr inbounds nuw [[AGG]], ptr [[RET]], i32 0, i32 2
59 // CHECK:   [[SECOND:%.*]] = load i8, ptr [[T0]], align 2
60 // CHECK:   [[T0:%.*]] = getelementptr inbounds nuw [[AGG]], ptr [[RET]], i32 0, i32 4
61 // CHECK:   [[THIRD:%.*]] = load float, ptr [[T0]], align 4
62 // CHECK:   [[T0:%.*]] = getelementptr inbounds nuw [[AGG]], ptr [[RET]], i32 0, i32 5
63 // CHECK:   [[FOURTH:%.*]] = load float, ptr [[T0]], align 4
64 // CHECK:   [[T0:%.*]] = insertvalue [[UAGG:{ i32, i8, float, float }]] poison, i32 [[FIRST]], 0
65 // CHECK:   [[T1:%.*]] = insertvalue [[UAGG]] [[T0]], i8 [[SECOND]], 1
66 // CHECK:   [[T2:%.*]] = insertvalue [[UAGG]] [[T1]], float [[THIRD]], 2
67 // CHECK:   [[T3:%.*]] = insertvalue [[UAGG]] [[T2]], float [[FOURTH]], 3
68 // CHECK:   ret [[UAGG]] [[T3]]
69 // CHECK-LABEL: define {{.*}} @take_struct_1(i32 %0, i8 %1, float %2, float %3)
70 // CHECK:   [[V:%.*]] = alloca [[REC]], align 4
71 // CHECK:   [[T0:%.*]] = getelementptr inbounds nuw [[AGG]], ptr [[V]], i32 0, i32 0
72 // CHECK:   store i32 %0, ptr [[T0]], align 4
73 // CHECK:   [[T0:%.*]] = getelementptr inbounds nuw [[AGG]], ptr [[V]], i32 0, i32 2
74 // CHECK:   store i8 %1, ptr [[T0]], align 2
75 // CHECK:   [[T0:%.*]] = getelementptr inbounds nuw [[AGG]], ptr [[V]], i32 0, i32 4
76 // CHECK:   store float %2, ptr [[T0]], align 4
77 // CHECK:   [[T0:%.*]] = getelementptr inbounds nuw [[AGG]], ptr [[V]], i32 0, i32 5
78 // CHECK:   store float %3, ptr [[T0]], align 4
79 // CHECK:   ret void
80 // CHECK-LABEL: define{{.*}} void @test_struct_1()
81 // CHECK:   [[TMP:%.*]] = alloca [[REC]], align 4
82 // CHECK:   [[CALL:%.*]] = call [[SWIFTCC:swiftcc]] [[UAGG]] @return_struct_1()
83 // CHECK:   [[T0:%.*]] = getelementptr inbounds nuw [[AGG]], ptr [[TMP]], i32 0, i32 0
84 // CHECK:   [[T1:%.*]] = extractvalue [[UAGG]] [[CALL]], 0
85 // CHECK:   store i32 [[T1]], ptr [[T0]], align 4
86 // CHECK:   [[T0:%.*]] = getelementptr inbounds nuw [[AGG]], ptr [[TMP]], i32 0, i32 2
87 // CHECK:   [[T1:%.*]] = extractvalue [[UAGG]] [[CALL]], 1
88 // CHECK:   store i8 [[T1]], ptr [[T0]], align 2
89 // CHECK:   [[T0:%.*]] = getelementptr inbounds nuw [[AGG]], ptr [[TMP]], i32 0, i32 4
90 // CHECK:   [[T1:%.*]] = extractvalue [[UAGG]] [[CALL]], 2
91 // CHECK:   store float [[T1]], ptr [[T0]], align 4
92 // CHECK:   [[T0:%.*]] = getelementptr inbounds nuw [[AGG]], ptr [[TMP]], i32 0, i32 5
93 // CHECK:   [[T1:%.*]] = extractvalue [[UAGG]] [[CALL]], 3
94 // CHECK:   store float [[T1]], ptr [[T0]], align 4
95 // CHECK:   [[T0:%.*]] = getelementptr inbounds nuw [[AGG]], ptr [[TMP]], i32 0, i32 0
96 // CHECK:   [[FIRST:%.*]] = load i32, ptr [[T0]], align 4
97 // CHECK:   [[T0:%.*]] = getelementptr inbounds nuw [[AGG]], ptr [[TMP]], i32 0, i32 2
98 // CHECK:   [[SECOND:%.*]] = load i8, ptr [[T0]], align 2
99 // CHECK:   [[T0:%.*]] = getelementptr inbounds nuw [[AGG]], ptr [[TMP]], i32 0, i32 4
100 // CHECK:   [[THIRD:%.*]] = load float, ptr [[T0]], align 4
101 // CHECK:   [[T0:%.*]] = getelementptr inbounds nuw [[AGG]], ptr [[TMP]], i32 0, i32 5
102 // CHECK:   [[FOURTH:%.*]] = load float, ptr [[T0]], align 4
103 // CHECK:   call [[SWIFTCC]] void @take_struct_1(i32 [[FIRST]], i8 [[SECOND]], float [[THIRD]], float [[FOURTH]])
104 // CHECK:   ret void
105 
106 struct struct_indirect_1 {
107   int x;
108   ~struct_indirect_1();
109 };
110 TEST(struct_indirect_1)
111 
112 // CHECK-LABEL: define {{.*}} void @return_struct_indirect_1({{.*}} dead_on_unwind noalias writable sret
113 
114 // Should not be byval.
115 // CHECK-LABEL: define {{.*}} void @take_struct_indirect_1(ptr noundef{{( %.*)?}})
116 
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 {
121   int x;
122 };
123 // CHECK-LABEL: define{{.*}} swiftcc void @test_struct_trivial(i32{{( %.*)?}})
124 extern "C" SWIFTCALL
125 void test_struct_trivial(struct_trivial triv) {}
126