Skip to content

Commit 669d2bb

Browse files
committed
[Clang][LoongArch] Pre-commit test for D156116
Differential Revision: https://reviews.llvm.org/D156114
1 parent c8bcc48 commit 669d2bb

File tree

1 file changed

+83
-0
lines changed

1 file changed

+83
-0
lines changed
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
// RUN: %clang_cc1 -triple loongarch64 -target-feature +f -target-feature +d -target-abi lp64d -emit-llvm %s -o - | \
2+
// RUN: FileCheck --check-prefix=CHECK-C %s
3+
// RUN: %clang_cc1 -triple loongarch64 -target-feature +f -target-feature +d -target-abi lp64d -emit-llvm %s -o - -x c++ | \
4+
// RUN: FileCheck --check-prefix=CHECK-CXX %s
5+
6+
// FIXME: This isn't currently respected.
7+
// Fields containing empty structs or unions are ignored when flattening
8+
// structs to examine whether the structs can be passed via FARs, even in C++.
9+
// But there is an exception that non-zero-length array of empty structures are
10+
// not ignored in C++. These rules are not documented in psABI <https://www.github.com/loongson/la-abi-specs>
11+
// but they match GCC behaviours.
12+
13+
#include <stdint.h>
14+
15+
struct empty { struct { struct { } e; }; };
16+
struct s1 { struct empty e; float f; };
17+
18+
// CHECK-C: define{{.*}} float @test_s1(float {{.*}})
19+
// CHECK-CXX: define{{.*}} i64 @_Z7test_s12s1(i64 {{.*}})
20+
struct s1 test_s1(struct s1 a) {
21+
return a;
22+
}
23+
24+
struct s2 { struct empty e; int32_t i; float f; };
25+
26+
// CHECK-C: define{{.*}} { i32, float } @test_s2(i32 {{.*}}, float {{.*}})
27+
// CHECK-CXX: define{{.*}} [2 x i64] @_Z7test_s22s2([2 x i64] {{.*}})
28+
struct s2 test_s2(struct s2 a) {
29+
return a;
30+
}
31+
32+
struct s3 { struct empty e; float f; float g; };
33+
34+
// CHECK-C: define{{.*}} { float, float } @test_s3(float {{.*}}, float {{.*}})
35+
// CHECK-CXX: define{{.*}} [2 x i64] @_Z7test_s32s3([2 x i64] {{.*}})
36+
struct s3 test_s3(struct s3 a) {
37+
return a;
38+
}
39+
40+
struct s4 { struct empty e; float __complex__ c; };
41+
42+
// CHECK-C: define{{.*}} { float, float } @test_s4(float {{.*}}, float {{.*}})
43+
// CHECK-CXX: define{{.*}} [2 x i64] @_Z7test_s42s4([2 x i64] {{.*}})
44+
struct s4 test_s4(struct s4 a) {
45+
return a;
46+
}
47+
48+
// An array of empty fields isn't ignored in C++ (this isn't explicit in the
49+
// psABI, but matches observed g++ behaviour).
50+
51+
struct s5 { struct empty e[1]; float f; };
52+
53+
// CHECK-C: define{{.*}} float @test_s5(float {{.*}})
54+
// CHECK-CXX: define{{.*}} i64 @_Z7test_s52s5(i64 {{.*}})
55+
struct s5 test_s5(struct s5 a) {
56+
return a;
57+
}
58+
59+
struct empty_arr { struct { struct { } e[1]; }; };
60+
struct s6 { struct empty_arr e; float f; };
61+
62+
// CHECK-C: define{{.*}} float @test_s6(float {{.*}})
63+
// CHECK-CXX: define{{.*}} i64 @_Z7test_s62s6(i64 {{.*}})
64+
struct s6 test_s6(struct s6 a) {
65+
return a;
66+
}
67+
68+
struct s7 { struct empty e[0]; float f; };
69+
70+
// CHECK-C: define{{.*}} float @test_s7(float {{.*}})
71+
// CHECK-CXX: define{{.*}} float @_Z7test_s72s7(float {{.*}})
72+
struct s7 test_s7(struct s7 a) {
73+
return a;
74+
}
75+
76+
struct empty_arr0 { struct { struct { } e[0]; }; };
77+
struct s8 { struct empty_arr0 e; float f; };
78+
79+
// CHECK-C: define{{.*}} float @test_s8(float {{.*}})
80+
// CHECK-CXX: define{{.*}} i64 @_Z7test_s82s8(i64 {{.*}})
81+
struct s8 test_s8(struct s8 a) {
82+
return a;
83+
}

0 commit comments

Comments
 (0)