This is the mail archive of the gcc-cvs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

r269760 - in /trunk/gcc: ChangeLog config/riscv...


Author: aburgess
Date: Mon Mar 18 10:42:53 2019
New Revision: 269760

URL: https://gcc.gnu.org/viewcvs?rev=269760&root=gcc&view=rev
Log:
gcc/riscv: Correctly ignore empty C++ structs when flattening for ABI

This fixes PR target/89627.

The RISC-V ABI document[1] says:

   For the purposes of this section, "struct" refers to a C struct
   with its hierarchy flattened, including any array fields. That is,
   struct { struct { float f[1]; } g[2]; } and struct { float f; float
   g; } are treated the same. Fields containing empty structs or
   unions are ignored while flattening, even in C++, unless they have
   nontrivial copy constructors or destructors.

However, this flattening only applies when one of the fields of the
flattened structure can be placed into a floating point register,
otherwise no flattening occurs.

Currently GCC fails to correctly consider that empty C++ structures
have a non-zero size when constructing the arguments from a flattened
structure, and as a result, trying to pass a C++ structure like this:

  struct sf { struct {} e; float f; };

Doesn't work correctly, GCC fails to take the offset of 'f' within
'sf' into account and will actually pass the space backing 'e' as the
contents of 'f'.

This patch fixes this so that 'f' will be passed correctly.  A couple
of new tests are added to cover this functionality.

[1] https://github.com/riscv/riscv-elf-psabi-doc/blob/master/riscv-elf.md

gcc/ChangeLog:

	PR target/89627
	* config/riscv/riscv.c (riscv_pass_fpr_single): Add offset
	parameter, and make use of it.
	(riscv_get_arg_info): Pass offset to riscv_pass_fpr_single.

gcc/testsuite/ChangeLog:

	PR target/89627
	* g++.target/riscv/call-with-empty-struct-float.C: New file.
	* g++.target/riscv/call-with-empty-struct-int.C: New file.
	* g++.target/riscv/call-with-empty-struct.H: New file.
	* g++.target/riscv/riscv.exp: New file.

Added:
    trunk/gcc/testsuite/g++.target/riscv/
    trunk/gcc/testsuite/g++.target/riscv/call-with-empty-struct-float.C
    trunk/gcc/testsuite/g++.target/riscv/call-with-empty-struct-int.C
    trunk/gcc/testsuite/g++.target/riscv/call-with-empty-struct.H
    trunk/gcc/testsuite/g++.target/riscv/riscv.exp
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/config/riscv/riscv.c
    trunk/gcc/testsuite/ChangeLog


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]