loongarch: ignore zero-size fields in calling convention
gcc/ * config/loongarch/loongarch.cc (loongarch_flatten_aggregate_field): Ignore empty fields for RECORD_TYPE. gcc/testsuite/ * gcc.target/loongarch/zero-size-field-pass.c: New test. * gcc.target/loongarch/zero-size-field-ret.c: New test.
This commit is contained in:
parent
ba949a6af4
commit
d1ee29fd7f
@ -329,6 +329,9 @@ loongarch_flatten_aggregate_field (const_tree type,
|
||||
if (!TYPE_P (TREE_TYPE (f)))
|
||||
return -1;
|
||||
|
||||
if (DECL_SIZE (f) && integer_zerop (DECL_SIZE (f)))
|
||||
continue;
|
||||
|
||||
HOST_WIDE_INT pos = offset + int_byte_position (f);
|
||||
n = loongarch_flatten_aggregate_field (TREE_TYPE (f), fields, n,
|
||||
pos);
|
||||
|
30
gcc/testsuite/gcc.target/loongarch/zero-size-field-pass.c
Normal file
30
gcc/testsuite/gcc.target/loongarch/zero-size-field-pass.c
Normal file
@ -0,0 +1,30 @@
|
||||
/* Test that LoongArch backend ignores zero-sized fields of aggregates in
|
||||
argument passing. */
|
||||
|
||||
/* { dg-do compile } */
|
||||
/* { dg-options "-O2 -mdouble-float -mabi=lp64d" } */
|
||||
/* { dg-final { scan-assembler "\\\$f1" } } */
|
||||
|
||||
struct test
|
||||
{
|
||||
int empty1[0];
|
||||
double empty2[0];
|
||||
int : 0;
|
||||
float x;
|
||||
long empty3[0];
|
||||
long : 0;
|
||||
float y;
|
||||
unsigned : 0;
|
||||
char empty4[0];
|
||||
};
|
||||
|
||||
extern void callee (struct test);
|
||||
|
||||
void
|
||||
caller (void)
|
||||
{
|
||||
struct test test;
|
||||
test.x = 114;
|
||||
test.y = 514;
|
||||
callee (test);
|
||||
}
|
28
gcc/testsuite/gcc.target/loongarch/zero-size-field-ret.c
Normal file
28
gcc/testsuite/gcc.target/loongarch/zero-size-field-ret.c
Normal file
@ -0,0 +1,28 @@
|
||||
/* Test that LoongArch backend ignores zero-sized fields of aggregates in
|
||||
returning. */
|
||||
|
||||
/* { dg-do compile } */
|
||||
/* { dg-options "-O2 -mdouble-float -mabi=lp64d" } */
|
||||
/* { dg-final { scan-assembler-not "\\\$r4" } } */
|
||||
|
||||
struct test
|
||||
{
|
||||
int empty1[0];
|
||||
double empty2[0];
|
||||
int : 0;
|
||||
float x;
|
||||
long empty3[0];
|
||||
long : 0;
|
||||
float y;
|
||||
unsigned : 0;
|
||||
char empty4[0];
|
||||
};
|
||||
|
||||
extern struct test callee (void);
|
||||
|
||||
float
|
||||
caller (void)
|
||||
{
|
||||
struct test test = callee ();
|
||||
return test.x + test.y;
|
||||
}
|
Loading…
Reference in New Issue
Block a user