This is the mail archive of the 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]

Re: [RS6000] PR61300 K&R incoming args

On 05/29/14 00:55, Alan Modra wrote:
One of the nice features of the ELFv2 ABI is that stack frames are
smaller compared to ELFv1.  We don't allocate a parameter save area
unless we actually use it.  However, for variable argument lists, we
kept the simple va_list type which is a pointer to the memory location
of the next parameter.  This means calls to variable argument list
functions must allocate the parameter save area, and hence calls to
unprototyped functions must also do so.

The wrinkle with K&R style C functions is that function *definitions*
may be unprototyped.  So when compiling a function body we can't use
!prototype_p() to say we have a parameter save area.  A call in some
other compilation unit might be prototyped and so not allocate a
parameter save area.  Another consequence of unprototyped function
definitions is that the return type and argument types may not be
available on the function type node.  Instead you need to look at the
return and arguments on the function decl.

Now, function.c always passes a decl to REG_PARM_STACK_SPACE, but
calls.c sometimes passes a decl and sometimes a type.  This latter
fact makes it necessary, I think, to define an
INCOMING_REG_PARM_STACK_SPACE used by function.c.  You can't blindly
use a decl from calls.c as that falls foul of C++..

The following implements this.  Bootstrapped and regression tested
powerpc64le-linux and powerpc64-linux all langs (except Ada since I
didn't have gnat installed.)  OK to apply?

	PR target/61300
	* doc/tm.texi: Regenerate.
	* function.c (INCOMING_REG_PARM_STACK_SPACE): Provide default.
	Use throughout in place of REG_PARM_STACK_SPACE.
	* config/rs6000/rs6000.c (rs6000_reg_parm_stack_space): Add
	"incoming" param.  Pass to rs6000_function_parms_need_stack.
	(rs6000_function_parms_need_stack): Add "incoming" param, ignore
	prototype_p when incoming.  Use function decl when incoming
	to handle K&R style functions.
	* config/rs6000/rs6000.h (REG_PARM_STACK_SPACE): Adjust.

Index: gcc/doc/
--- gcc/doc/	(revision 210919)
+++ gcc/doc/	(working copy)
@@ -3499,6 +3499,13 @@ which.
  @c above is overfull.  not sure what to do.  --mew 5feb93  did
  @c something, not sure if it looks good.  --mew 10feb93

+@defmac INCOMING_REG_PARM_STACK_SPACE (@var{fndecl})
+Like @code{REG_PARM_STACK_SPACE}, but for incoming register arguments.
+Define this macro if space guaranteed when compiling a function body
+is different to space required when making a call, a situation that
+can arise with unprototyped functions.
+@end defmac
Might be better to clarify ever-so-slightly with "unprototyped function definitions" or "K&R style function defintions". Similarly for the comment for the definition in rs6000.h

Seems like a reasonable way to simplify this stuff a bit. Certainly makes it easier to review.

There's a few other references to REG_PARM_STACK_SPACE in comments, can you review those and change to INCOMING_REG_PARM_STACK_SPACE if necessary.

I'm certainly not a PPC expert, but I can generally see what you're doing in rs6000.c. I'm going to assume you got it right and if not you'll address any issues.

OK to apply.

Thanks for your patience,

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