Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / CodeGen / RISCV / abi-empty-structs.c
blobc48a2891627d425fa48673bca30abb92ec8494a8
1 // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --filter "^define |^entry:" --version 2
2 // RUN: %clang_cc1 -triple riscv32 -target-feature +f -target-abi ilp32f -emit-llvm %s -o - \
3 // RUN: | FileCheck -check-prefixes=CHECK-C,CHECK32-C %s
4 // RUN: %clang_cc1 -triple riscv32 -target-feature +f -target-feature +d -target-abi ilp32d -emit-llvm %s -o - \
5 // RUN: | FileCheck -check-prefixes=CHECK-C,CHECK32-C %s
6 // RUN: %clang_cc1 -triple riscv64 -target-feature +f -target-abi lp64f -emit-llvm %s -o - \
7 // RUN: | FileCheck -check-prefixes=CHECK-C,CHECK64-C %s
8 // RUN: %clang_cc1 -triple riscv64 -target-feature +f -target-feature +d -target-abi lp64d -emit-llvm %s -o - \
9 // RUN: | FileCheck -check-prefixes=CHECK-C,CHECK64-C %s
10 // RUN: %clang_cc1 -x c++ -triple riscv32 -target-feature +f -target-abi ilp32f -emit-llvm %s -o - \
11 // RUN: | FileCheck -check-prefixes=CHECK-CXX,CHECK32-CXX %s
12 // RUN: %clang_cc1 -x c++ -triple riscv32 -target-feature +f -target-feature +d -target-abi ilp32d -emit-llvm %s -o - \
13 // RUN: | FileCheck -check-prefixes=CHECK-CXX,CHECK32-CXX %s
14 // RUN: %clang_cc1 -x c++ -triple riscv64 -target-feature +f -target-abi lp64f -emit-llvm %s -o - \
15 // RUN: | FileCheck -check-prefixes=CHECK-CXX,CHECK64-CXX %s
16 // RUN: %clang_cc1 -x c++ -triple riscv64 -target-feature +f -target-feature +d -target-abi lp64d -emit-llvm %s -o - \
17 // RUN: | FileCheck -check-prefixes=CHECK-CXX,CHECK64-CXX %s
19 #include <stdint.h>
21 // Fields containing empty structs or unions are ignored when flattening
22 // structs for the hard FP ABIs, even in C++. The rules for arrays of empty
23 // structs or unions are subtle and documented in
24 // <https://github.com/riscv-non-isa/riscv-elf-psabi-doc/blob/master/riscv-cc.adoc#hardware-floating-point-calling-convention>.
26 struct empty { struct { struct { } e; }; };
27 struct s1 { struct empty e; float f; };
29 // CHECK-C-LABEL: define dso_local float @test_s1
30 // CHECK-C-SAME: (float [[TMP0:%.*]]) #[[ATTR0:[0-9]+]] {
31 // CHECK-C: entry:
33 // CHECK-CXX-LABEL: define dso_local float @_Z7test_s12s1
34 // CHECK-CXX-SAME: (float [[TMP0:%.*]]) #[[ATTR0:[0-9]+]] {
35 // CHECK-CXX: entry:
37 struct s1 test_s1(struct s1 a) {
38 return a;
41 struct s2 { struct empty e; int32_t i; float f; };
43 // CHECK-C-LABEL: define dso_local { i32, float } @test_s2
44 // CHECK-C-SAME: (i32 [[TMP0:%.*]], float [[TMP1:%.*]]) #[[ATTR0]] {
45 // CHECK-C: entry:
47 // CHECK-CXX-LABEL: define dso_local { i32, float } @_Z7test_s22s2
48 // CHECK-CXX-SAME: (i32 [[TMP0:%.*]], float [[TMP1:%.*]]) #[[ATTR0]] {
49 // CHECK-CXX: entry:
51 struct s2 test_s2(struct s2 a) {
52 return a;
55 struct s3 { struct empty e; float f; float g; };
57 // CHECK-C-LABEL: define dso_local { float, float } @test_s3
58 // CHECK-C-SAME: (float [[TMP0:%.*]], float [[TMP1:%.*]]) #[[ATTR0]] {
59 // CHECK-C: entry:
61 // CHECK-CXX-LABEL: define dso_local { float, float } @_Z7test_s32s3
62 // CHECK-CXX-SAME: (float [[TMP0:%.*]], float [[TMP1:%.*]]) #[[ATTR0]] {
63 // CHECK-CXX: entry:
65 struct s3 test_s3(struct s3 a) {
66 return a;
69 struct s4 { struct empty e; float __complex__ c; };
71 // CHECK-C-LABEL: define dso_local { float, float } @test_s4
72 // CHECK-C-SAME: (float [[TMP0:%.*]], float [[TMP1:%.*]]) #[[ATTR0]] {
73 // CHECK-C: entry:
75 // CHECK-CXX-LABEL: define dso_local { float, float } @_Z7test_s42s4
76 // CHECK-CXX-SAME: (float [[TMP0:%.*]], float [[TMP1:%.*]]) #[[ATTR0]] {
77 // CHECK-CXX: entry:
79 struct s4 test_s4(struct s4 a) {
80 return a;
83 // An array of empty fields isn't ignored in C++ (this isn't explicit in the
84 // psABI, but matches observed g++ behaviour).
86 struct s5 { struct empty e[1]; float f; };
88 // CHECK-C-LABEL: define dso_local float @test_s5
89 // CHECK-C-SAME: (float [[TMP0:%.*]]) #[[ATTR0]] {
90 // CHECK-C: entry:
92 // CHECK32-CXX-LABEL: define dso_local [2 x i32] @_Z7test_s52s5
93 // CHECK32-CXX-SAME: ([2 x i32] [[A_COERCE:%.*]]) #[[ATTR0]] {
94 // CHECK32-CXX: entry:
96 // CHECK64-CXX-LABEL: define dso_local i64 @_Z7test_s52s5
97 // CHECK64-CXX-SAME: (i64 [[A_COERCE:%.*]]) #[[ATTR0]] {
98 // CHECK64-CXX: entry:
100 struct s5 test_s5(struct s5 a) {
101 return a;
104 struct empty_arr { struct { struct { } e[1]; }; };
105 struct s6 { struct empty_arr e; float f; };
107 // CHECK-C-LABEL: define dso_local float @test_s6
108 // CHECK-C-SAME: (float [[TMP0:%.*]]) #[[ATTR0]] {
109 // CHECK-C: entry:
111 // CHECK32-CXX-LABEL: define dso_local [2 x i32] @_Z7test_s62s6
112 // CHECK32-CXX-SAME: ([2 x i32] [[A_COERCE:%.*]]) #[[ATTR0]] {
113 // CHECK32-CXX: entry:
115 // CHECK64-CXX-LABEL: define dso_local i64 @_Z7test_s62s6
116 // CHECK64-CXX-SAME: (i64 [[A_COERCE:%.*]]) #[[ATTR0]] {
117 // CHECK64-CXX: entry:
119 struct s6 test_s6(struct s6 a) {
120 return a;
123 struct s7 { struct empty e[0]; float f; };
125 // CHECK-C-LABEL: define dso_local float @test_s7
126 // CHECK-C-SAME: (float [[TMP0:%.*]]) #[[ATTR0]] {
127 // CHECK-C: entry:
129 // CHECK-CXX-LABEL: define dso_local float @_Z7test_s72s7
130 // CHECK-CXX-SAME: (float [[TMP0:%.*]]) #[[ATTR0]] {
131 // CHECK-CXX: entry:
133 struct s7 test_s7(struct s7 a) {
134 return a;
137 struct empty_arr0 { struct { struct { } e[0]; }; };
138 struct s8 { struct empty_arr0 e; float f; };
140 // CHECK-C-LABEL: define dso_local float @test_s8
141 // CHECK-C-SAME: (float [[TMP0:%.*]]) #[[ATTR0]] {
142 // CHECK-C: entry:
144 // CHECK-CXX-LABEL: define dso_local float @_Z7test_s82s8
145 // CHECK-CXX-SAME: (float [[TMP0:%.*]]) #[[ATTR0]] {
146 // CHECK-CXX: entry:
148 struct s8 test_s8(struct s8 a) {
149 return a;
152 struct s9 {
153 struct empty e;
156 // CHECK-C-LABEL: define dso_local void @test_s9
157 // CHECK-C-SAME: () #[[ATTR0]] {
158 // CHECK-C: entry:
160 // CHECK32-CXX-LABEL: define dso_local void @_Z7test_s92s9
161 // CHECK32-CXX-SAME: (i32 [[A_COERCE:%.*]]) #[[ATTR0]] {
162 // CHECK32-CXX: entry:
164 // CHECK64-CXX-LABEL: define dso_local void @_Z7test_s92s9
165 // CHECK64-CXX-SAME: (i64 [[A_COERCE:%.*]]) #[[ATTR0]] {
166 // CHECK64-CXX: entry:
168 void test_s9(struct s9 a) {}
170 //// NOTE: These prefixes are unused and the list is autogenerated. Do not add tests below this line:
171 // CHECK32-C: {{.*}}
172 // CHECK64-C: {{.*}}