143 lines · c
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 %s3// 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 %s5 6// Fields containing empty structs are ignored when flattening7// structs to examine whether the structs can be passed via FARs, even in C++.8// But there is an exception that non-zero-length array of empty structures are9// not ignored in C++. These rules are not documented in psABI <https://www.github.com/loongson/la-abi-specs>10// but they match GCC behaviours.11 12#include <stdint.h>13 14struct empty { struct { struct { } e; }; };15struct s1 { struct empty e; float f; };16 17// CHECK-C: define{{.*}} float @test_s1(float {{.*}})18// CHECK-CXX: define{{.*}} float @_Z7test_s12s1(float {{.*}})19struct s1 test_s1(struct s1 a) {20 return a;21}22 23struct s2 { struct empty e; int32_t i; float f; };24 25// CHECK-C: define{{.*}} { i32, float } @test_s2(i32 {{.*}}, float {{.*}})26// CHECK-CXX: define{{.*}} { i32, float } @_Z7test_s22s2(i32 {{.*}}, float {{.*}})27struct s2 test_s2(struct s2 a) {28 return a;29}30 31struct s3 { struct empty e; float f; float g; };32 33// CHECK-C: define{{.*}} { float, float } @test_s3(float {{.*}}, float {{.*}})34// CHECK-CXX: define{{.*}} { float, float } @_Z7test_s32s3(float {{.*}}, float {{.*}})35struct s3 test_s3(struct s3 a) {36 return a;37}38 39struct s4 { struct empty e; float __complex__ c; };40 41// CHECK-C: define{{.*}} { float, float } @test_s4(float {{.*}}, float {{.*}})42// CHECK-CXX: define{{.*}} { float, float } @_Z7test_s42s4(float {{.*}}, float {{.*}})43struct s4 test_s4(struct s4 a) {44 return a;45}46 47// An array of empty fields isn't ignored in C++ (this isn't explicit in the48// psABI, but matches observed g++ behaviour).49 50struct s5 { struct empty e[1]; float f; };51 52// CHECK-C: define{{.*}} float @test_s5(float {{.*}})53// CHECK-CXX: define{{.*}} i64 @_Z7test_s52s5(i64 {{.*}})54struct s5 test_s5(struct s5 a) {55 return a;56}57 58struct empty_arr { struct { struct { } e[1]; }; };59struct s6 { struct empty_arr e; float f; };60 61// CHECK-C: define{{.*}} float @test_s6(float {{.*}})62// CHECK-CXX: define{{.*}} i64 @_Z7test_s62s6(i64 {{.*}})63struct s6 test_s6(struct s6 a) {64 return a;65}66 67struct s7 { struct empty e[0]; float f; };68 69// CHECK-C: define{{.*}} float @test_s7(float {{.*}})70// CHECK-CXX: define{{.*}} float @_Z7test_s72s7(float {{.*}})71struct s7 test_s7(struct s7 a) {72 return a;73}74 75struct empty_arr0 { struct { struct { } e[0]; }; };76struct s8 { struct empty_arr0 e; float f; };77 78// CHECK-C: define{{.*}} float @test_s8(float {{.*}})79// CHECK-CXX: define{{.*}} float @_Z7test_s82s8(float {{.*}})80struct s8 test_s8(struct s8 a) {81 return a;82}83 84/// Note: Below tests check how empty structs are passed while above tests check85/// empty structs as fields of container struct are ignored when flattening86/// structs to examine whether the container structs can be passed via FARs.87 88// CHECK-C: define{{.*}} void @test_s9()89// CHECK-CXX: define{{.*}} i64 @_Z7test_s92s9(i64 {{.*}})90struct s9 { struct empty e; };91struct s9 test_s9(struct s9 a) {92 return a;93}94 95// CHECK-C: define{{.*}} void @test_s10()96// CHECK-CXX: define{{.*}} i64 @_Z8test_s103s10(i64 {{.*}})97struct s10 { };98struct s10 test_s10(struct s10 a) {99 return a;100}101 102// CHECK-C: define{{.*}} void @test_s11()103// CHECK-CXX: define{{.*}} i64 @_Z8test_s113s11(i64 {{.*}})104struct s11 { struct { } s; };105struct s11 test_s11(struct s11 a) {106 return a;107}108 109// CHECK-C: define{{.*}} void @test_s12()110// CHECK-CXX: define{{.*}} void @_Z8test_s123s12()111struct s12 { int i[0]; };112struct s12 test_s12(struct s12 a) {113 return a;114}115 116// CHECK-C: define{{.*}} void @test_s13()117// CHECK-CXX: define{{.*}} void @_Z8test_s133s13()118struct s13 { struct { } s[0]; };119struct s13 test_s13(struct s13 a) {120 return a;121}122 123// CHECK-C: define{{.*}} void @test_s14()124// CHECK-CXX: define{{.*}} i64 @_Z8test_s143s14(i64 {{.*}})125struct s14 { struct { } s[1]; };126struct s14 test_s14(struct s14 a) {127 return a;128}129 130// CHECK-C: define{{.*}} void @test_s15()131// CHECK-CXX: define{{.*}} i64 @_Z8test_s153s15(i64 {{.*}})132struct s15 { int : 0; };133struct s15 test_s15(struct s15 a) {134 return a;135}136 137// CHECK-C: define{{.*}} i64 @test_s16(i64 {{.*}})138// CHECK-CXX: define{{.*}} i64 @_Z8test_s163s16(i64 {{.*}})139struct s16 { int : 1; };140struct s16 test_s16(struct s16 a) {141 return a;142}143