[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / CodeGen / cmse-clear-arg.c
blobde77d637ef43f05298dc727a389f194a1330194d
1 // RUN: %clang_cc1 -triple thumbv8m.main -O0 -mcmse -emit-llvm %s -o - | \
2 // RUN: FileCheck %s --check-prefixes=CHECK,CHECK-LE,CHECK-SOFTFP
3 // RUN: %clang_cc1 -triple thumbebv8m.main -O0 -mcmse -emit-llvm %s -o - | \
4 // RUN: FileCheck %s --check-prefixes=CHECK,CHECK-BE,CHECK-SOFTFP
5 // RUN: %clang_cc1 -triple thumbv8m.main -O2 -mcmse -emit-llvm %s -o - | \
6 // RUN: FileCheck %s --check-prefixes=CHECK,CHECK-LE,CHECK-SOFTFP
7 // RUN: %clang_cc1 -triple thumbebv8m.main -O2 -mcmse -emit-llvm %s -o - | \
8 // RUN: FileCheck %s --check-prefixes=CHECK,CHECK-BE,CHECK-SOFTFP
9 // RUN: %clang_cc1 -triple thumbv8m.main -O0 -mcmse -mfloat-abi hard \
10 // RUN: -emit-llvm %s -o - | \
11 // RUN: FileCheck %s --check-prefixes=CHECK,CHECK-LE,CHECK-HARDFP
13 // We don't really need to repeat *all* the test cases from cmse-clear-return.c
14 // as it won't increase test coverage.
16 // : Memory layout | Mask
17 // LE: .......1 ........ ........ ........ | 0x00000001/1
18 // BE: 1....... ........ ........ ........ | 0x80000000/-2147483648
19 typedef struct T0 {
20 int a : 1, : 31;
21 } T0;
23 void __attribute__((cmse_nonsecure_call)) (*g0)(T0);
25 T0 t0;
26 void f0(void) { g0(t0); }
27 // CHECK: define {{.*}} @f0()
28 // CHECK-LE: %[[V0:.*]] = and i32 {{.*}}, 1
29 // CHECK-BE: %[[V0:.*]] = and i32 {{.*}}, -2147483648
30 // CHECK: %[[V1:.*]] = insertvalue [1 x i32] poison, i32 %[[V0]], 0
31 // CHECK: call {{.*}} void %0([1 x i32] %[[V1]])
33 // LE: 11111111 111111.. 11111111 11111111 0xfffffcff/-769
34 // BE: 11111111 ..111111 11111111 11111111 0xff3fffff/-12582913
35 typedef struct T8 {
36 struct T80 {
37 char a;
38 char : 2, b : 6;
39 } a;
40 short b;
41 } T8;
43 T8 t8;
44 void __attribute__((cmse_nonsecure_call)) (*g8)(T8);
45 void f8(void) { g8(t8); }
46 // CHECK: define {{.*}} @f8()
47 // CHECK-LE: %[[V0:.*]] = and i32 {{.*}}, -769
48 // CHECK-BE: %[[V0:.*]] = and i32 {{.*}}, -12582913
49 // CHECK: %[[V1:.*]] = insertvalue [1 x i32] poison, i32 %[[V0]], 0
50 // CHECK: call {{.*}} void %0([1 x i32] %[[V1]])
52 // LE(0): 11111111 ........ 11111111 11111111 0xffff00ff/-65281
53 // LE(4): ...111.. 11111... 11111111 .....111 0x7fff81c/134215708
54 // BE(0): 11111111 ........ 11111111 11111111 0xff00ffff/-16711681
55 // BE(4): ..111... ...11111 11111111 111..... 0x381fffe0/941621216
56 typedef struct T15 {
57 char a;
58 short b;
59 int : 2, c : 3, : 6, d : 16;
60 } T15;
62 T15 t15;
64 void __attribute__((cmse_nonsecure_call)) (*g15_0)(T15);
65 void f15_0(void) {
66 g15_0(t15);
68 // CHECK: define {{.*}}@f15_0()
69 // CHECK: %[[FN:.*]] = load {{.*}} @g15_0
70 // CHECK-LE: %cmse.clear = and i32 {{.*}}, -65281
71 // CHECK-BE: %cmse.clear = and i32 {{.*}}, -16711681
72 // CHECK: %[[R0:.*]] = insertvalue [2 x i32] poison, i32 %cmse.clear, 0
73 // CHECK-LE: %cmse.clear1 = and i32 {{.*}}, 134215708
74 // CHECK-BE: %cmse.clear1 = and i32 {{.*}}, 941621216
75 // CHECK: %[[R1:.*]] = insertvalue [2 x i32] %[[R0]], i32 %cmse.clear1, 1
76 // CHECK: call {{.*}} void %[[FN]]([2 x i32] %[[R1]])
78 void __attribute__((cmse_nonsecure_call)) (*g15_1)(int, int, int, T15);
79 void f15_1(void) {
80 g15_1(0, 1, 2, t15);
82 // CHECK: define {{.*}}@f15_1()
83 // CHECK: %[[FN:.*]] = load {{.*}} @g15_1
84 // CHECK-LE: %cmse.clear = and i32 {{.*}}, -65281
85 // CHECK-BE: %cmse.clear = and i32 {{.*}}, -16711681
86 // CHECK: %[[R0:.*]] = insertvalue [2 x i32] poison, i32 %cmse.clear, 0
87 // CHECK-LE: %cmse.clear1 = and i32 {{.*}}, 134215708
88 // CHECK-BE: %cmse.clear1 = and i32 {{.*}}, 941621216
89 // CHECK: %[[R1:.*]] = insertvalue [2 x i32] %[[R0]], i32 %cmse.clear1, 1
90 // CHECK: call {{.*}} void %[[FN]](i32 noundef 0, i32 noundef 1, i32 noundef 2, [2 x i32] %[[R1]])
92 // LE: 11111111 ........ 11111111 11111111 1111.... ...11111 ........ .111111.
93 // LE: 0xff00fffff01f007e/9079291968726434047
94 // BE: 11111111 ........ 11111111 11111111 ....1111 11111... ........ .111111.
95 // BE: 0xff00ffff0ff8007e/-71776123088273282
97 typedef struct T16 {
98 char a;
99 short b;
100 long long : 4, c : 9, : 12, d : 6;
101 } T16;
103 T16 t16;
105 void __attribute__((cmse_nonsecure_call)) (*g16_0)(T16);
106 void f16_0(void) {
107 g16_0(t16);
109 // CHECK: define {{.*}} @f16_0()
110 // CHECK: %[[FN:.*]] = load {{.*}} @g16_0
111 // CHECK-LE: %cmse.clear = and i64 {{.*}}, 9079291968726434047
112 // CHECK-BE: %cmse.clear = and i64 {{.*}}, -71776123088273282
113 // CHECK: %[[R:.*]] = insertvalue [1 x i64] poison, i64 %cmse.clear, 0
114 // CHECK: call {{.*}} void %0([1 x i64] %[[R]])
117 // LE0: 1111..11 .......1 1111..11 .......1 1111..11 .......1 1111..11 .......1
118 // LE4: 1111..11 .......1 1111..11 .......1 11111111 11111111 11111111 ........
119 // LE : 0x01f301f3/32702963 * 3 + 0x00ffffff/16777215
120 // BE0: 11..1111 1....... 11..1111 1....... 11..1111 1....... 11..1111 1.......
121 // BE4: 11..1111 1....... 11..1111 1....... 11111111 11111111 11111111 ........
122 // BE : 0xcf80cf80/-813641856 * 3 + 0xffffff00/-256
124 typedef struct T18 {
125 struct T180 {
126 short a : 2;
127 short : 2, b : 5;
128 } a[2][3];
129 char b[3];
130 char c[];
131 } T18;
133 T18 t18;
135 void __attribute__((cmse_nonsecure_call)) (*g18)(T18);
136 void f18(void) {
137 g18(t18);
139 // CHECK: define {{.*}} @f18()
140 // CHECK: %[[FN:.*]] = load {{.*}} @g18
141 // CHECK-LE: %cmse.clear = and i32 {{.*}}, 32702963
142 // CHECK-BE: %cmse.clear = and i32 {{.*}}, -813641856
143 // CHECK: %[[R0:.*]] = insertvalue [4 x i32] poison, i32 %cmse.clear, 0
144 // CHECK-LE: %cmse.clear1 = and i32 {{.*}}, 32702963
145 // CHECK-BE: %cmse.clear1 = and i32 {{.*}}, -813641856
146 // CHECK: %[[R1:.*]] = insertvalue [4 x i32] %[[R0]], i32 %cmse.clear1, 1
147 // CHECK-LE: %cmse.clear2 = and i32 {{.*}}, 32702963
148 // CHECK-BE: %cmse.clear2 = and i32 {{.*}}, -813641856
149 // CHECK: %[[R2:.*]] = insertvalue [4 x i32] %[[R1]], i32 %cmse.clear2, 2
150 // CHECK-LE: %cmse.clear3 = and i32 {{.*}}, 16777215
151 // CHECK-BE: %cmse.clear3 = and i32 {{.*}}, -256
152 // CHECK: %[[R3:.*]] = insertvalue [4 x i32] %[[R2]], i32 %cmse.clear3, 3
153 // CHECK: call {{.*}} void %[[FN]]([4 x i32] %[[R3]])
155 // LE: 11111111 11111111 ..111... ..111... 0x3838ffff/943259647
156 // BE: 11111111 11111111 ...111.. ...111.. 0xffff1c1c/-58340
157 typedef union T19 {
158 short a;
159 struct T190 {
160 char : 3, a : 3;
161 } b[4];
162 } T19;
164 T19 t19;
165 void __attribute__((cmse_nonsecure_call)) (*g19)(T19);
166 void f19(void) {
167 g19(t19);
169 // CHECK: define {{.*}} @f19()
170 // CHECK: %[[FN:.*]] = load {{.*}} @g19
171 // CHECK-LE: %cmse.clear = and i32 {{.*}}, 943259647
172 // CHECK-BE: %cmse.clear = and i32 {{.*}}, -58340
173 // CHECK: %[[R:.*]] = insertvalue [1 x i32] poison, i32 %cmse.clear, 0
174 // CHECK: call {{.*}} void %[[FN]]([1 x i32] %[[R]])
177 typedef struct T20 {
178 float a[2];
179 } T20;
181 T20 t20;
182 void __attribute__((cmse_nonsecure_call)) (*g20)(T20);
183 void f20(void) {
184 g20(t20);
186 // CHECK: define {{.*}} @f20()
187 // CHECK: %[[FN:.*]] = load {{.*}} @g20
188 // CHECK-SOFTFP: call arm_aapcscc void %[[FN]]([2 x i32]
189 // CHECK-HARDFP: call arm_aapcs_vfpcc void %[[FN]](%struct.T20