[clang] 669d2bb - [Clang][LoongArch] Pre-commit test for D156116

Weining Lu via cfe-commits cfe-commits at lists.llvm.org
Mon Jul 24 18:00:08 PDT 2023


Author: Weining Lu
Date: 2023-07-25T08:59:40+08:00
New Revision: 669d2bbc837ee56d6bb05d5d55615246fc8b6b5c

URL: https://github.com/llvm/llvm-project/commit/669d2bbc837ee56d6bb05d5d55615246fc8b6b5c
DIFF: https://github.com/llvm/llvm-project/commit/669d2bbc837ee56d6bb05d5d55615246fc8b6b5c.diff

LOG: [Clang][LoongArch] Pre-commit test for D156116

Differential Revision: https://reviews.llvm.org/D156114

Added: 
    clang/test/CodeGen/LoongArch/abi-lp64d-empty-structs.c

Modified: 
    

Removed: 
    


################################################################################
diff  --git a/clang/test/CodeGen/LoongArch/abi-lp64d-empty-structs.c b/clang/test/CodeGen/LoongArch/abi-lp64d-empty-structs.c
new file mode 100644
index 00000000000000..3a65b90e48e0e0
--- /dev/null
+++ b/clang/test/CodeGen/LoongArch/abi-lp64d-empty-structs.c
@@ -0,0 +1,83 @@
+// RUN: %clang_cc1 -triple loongarch64 -target-feature +f -target-feature +d -target-abi lp64d -emit-llvm %s -o - | \
+// RUN:   FileCheck --check-prefix=CHECK-C %s
+// RUN: %clang_cc1 -triple loongarch64 -target-feature +f -target-feature +d -target-abi lp64d -emit-llvm %s -o - -x c++ | \
+// RUN:   FileCheck --check-prefix=CHECK-CXX %s
+
+// FIXME: This isn't currently respected.
+// Fields containing empty structs or unions are ignored when flattening
+// structs to examine whether the structs can be passed via FARs, even in C++.
+// But there is an exception that non-zero-length array of empty structures are
+// not ignored in C++. These rules are not documented in psABI <https://www.github.com/loongson/la-abi-specs>
+// but they match GCC behaviours.
+
+#include <stdint.h>
+
+struct empty { struct { struct { } e; }; };
+struct s1 { struct empty e; float f; };
+
+// CHECK-C: define{{.*}} float @test_s1(float {{.*}})
+// CHECK-CXX: define{{.*}} i64 @_Z7test_s12s1(i64 {{.*}})
+struct s1 test_s1(struct s1 a) {
+  return a;
+}
+
+struct s2 { struct empty e; int32_t i; float f; };
+
+// CHECK-C: define{{.*}} { i32, float } @test_s2(i32 {{.*}}, float {{.*}})
+// CHECK-CXX: define{{.*}} [2 x i64] @_Z7test_s22s2([2 x i64] {{.*}})
+struct s2 test_s2(struct s2 a) {
+  return a;
+}
+
+struct s3 { struct empty e; float f; float g; };
+
+// CHECK-C: define{{.*}} { float, float } @test_s3(float {{.*}}, float {{.*}})
+// CHECK-CXX: define{{.*}} [2 x i64] @_Z7test_s32s3([2 x i64] {{.*}})
+struct s3 test_s3(struct s3 a) {
+  return a;
+}
+
+struct s4 { struct empty e; float __complex__ c; };
+
+// CHECK-C: define{{.*}} { float, float } @test_s4(float {{.*}}, float {{.*}})
+// CHECK-CXX: define{{.*}} [2 x i64] @_Z7test_s42s4([2 x i64] {{.*}})
+struct s4 test_s4(struct s4 a) {
+  return a;
+}
+
+// An array of empty fields isn't ignored in C++ (this isn't explicit in the
+// psABI, but matches observed g++ behaviour).
+
+struct s5 { struct empty e[1]; float f; };
+
+// CHECK-C: define{{.*}} float @test_s5(float {{.*}})
+// CHECK-CXX: define{{.*}} i64 @_Z7test_s52s5(i64 {{.*}})
+struct s5 test_s5(struct s5 a) {
+  return a;
+}
+
+struct empty_arr { struct { struct { } e[1]; }; };
+struct s6 { struct empty_arr e; float f; };
+
+// CHECK-C: define{{.*}} float @test_s6(float {{.*}})
+// CHECK-CXX: define{{.*}} i64 @_Z7test_s62s6(i64 {{.*}})
+struct s6 test_s6(struct s6 a) {
+  return a;
+}
+
+struct s7 { struct empty e[0]; float f; };
+
+// CHECK-C: define{{.*}} float @test_s7(float {{.*}})
+// CHECK-CXX: define{{.*}} float @_Z7test_s72s7(float {{.*}})
+struct s7 test_s7(struct s7 a) {
+  return a;
+}
+
+struct empty_arr0 { struct { struct { } e[0]; }; };
+struct s8 { struct empty_arr0 e; float f; };
+
+// CHECK-C: define{{.*}} float @test_s8(float {{.*}})
+// CHECK-CXX: define{{.*}} i64 @_Z7test_s82s8(i64 {{.*}})
+struct s8 test_s8(struct s8 a) {
+  return a;
+}


        


More information about the cfe-commits mailing list