public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
From: amodra@bigpond.net.au
To: gcc-gnats@gcc.gnu.org
Subject: target/10397: powerpc64 aggregate pass by value
Date: Mon, 14 Apr 2003 09:36:00 -0000	[thread overview]
Message-ID: <20030414092647.7407.qmail@sources.redhat.com> (raw)


>Number:         10397
>Category:       target
>Synopsis:       powerpc64 aggregate pass by value
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon Apr 14 09:36:00 UTC 2003
>Closed-Date:
>Last-Modified:
>Originator:     amodra@bigpond.net.au
>Release:        All current gcc-3.x branches
>Organization:
>Environment:

>Description:
gcc exhibits a number of incompatibilities with the powerpc64
ABI with regards to passing structures by value.  The
attached testcase shows one particular problem, that argument
padding on certain structures differs between the reg param
area and the stack param area.  This breaks va_arg.

I'd like to add the testcase as gcc.dg/struct-by-value-2.c
(in gcc.dg because it takes a rather long time to compile).
>How-To-Repeat:

>Fix:
The following fix is a minimal change.  It might be better
to consistently pad small structures downward or upward,
but that is more likely to break compatibility with
existing objects.

Index: gcc/config/rs6000/rs6000.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/rs6000/rs6000.c,v
retrieving revision 1.457
diff -u -p -r1.457 rs6000.c
--- gcc/config/rs6000/rs6000.c	13 Apr 2003 17:51:07 -0000	1.457
+++ gcc/config/rs6000/rs6000.c	14 Apr 2003 06:11:22 -0000
@@ -3165,7 +3165,14 @@ function_arg_padding (mode, type)
      enum machine_mode mode;
      tree type;
 {
-  if (type != 0 && AGGREGATE_TYPE_P (type))
+  /* FIXME.  gcc currently ignores padding direction for structures of
+     1, 2 and 4 bytes in size when the structure is passed in the reg
+     param area, padding such structures downward.  For the sake of
+     va_arg we need to do the same outside the reg param area, which
+     is why we test the mode here rather than using AGGREGATE_TYPE_P.
+     FIXME too.  -mstrict-align also affects which way multi-component
+     2 and 4 byte structures are padded.  */
+  if (mode == BLKmode)
     return upward;
 
   /* This is the default definition.  */
>Release-Note:
>Audit-Trail:
>Unformatted:
----gnatsweb-attachment----
Content-Type: text/plain; name="struct-by-value-2.c"
Content-Disposition: inline; filename="struct-by-value-2.c"

/* Test structure passing by value.  */
/* { dg-do run } */
/* { dg-options "-O2" } */

#include <stdarg.h>

#if 0
#include <stdio.h>
#define DEBUG_FPUTS(x) fputs (x, stdout)
#define DEBUG_DOT putc ('.', stdout)
#define DEBUG_NL putc ('\n', stdout)
#else
#define DEBUG_FPUTS(x)
#define DEBUG_DOT
#define DEBUG_NL
#endif

#define T(N, NAME, TYPE)					\
struct S##NAME##N { TYPE i[N]; };				\
struct S##NAME##N g1s##NAME##N, g2s##NAME##N;			\
struct S##NAME##N g3s##NAME##N, g4s##NAME##N;			\
struct S##NAME##N g5s##NAME##N, g6s##NAME##N;			\
struct S##NAME##N g7s##NAME##N, g8s##NAME##N;			\
struct S##NAME##N g9s##NAME##N, g10s##NAME##N;			\
struct S##NAME##N g11s##NAME##N, g12s##NAME##N;			\
struct S##NAME##N g13s##NAME##N, g14s##NAME##N;			\
struct S##NAME##N g15s##NAME##N, g16s##NAME##N;			\
								\
void								\
init##NAME##N (struct S##NAME##N *p, int i)			\
{								\
  int j;							\
  for (j = 0; j < N; j++)					\
    p->i[j] = i + j;						\
}								\
								\
void								\
check##NAME##N (struct S##NAME##N *p, int i)			\
{								\
  int j;							\
  for (j = 0; j < N; j++)					\
    if (p->i[j] != (TYPE) (i + j))				\
      {								\
	DEBUG_NL;						\
	abort ();						\
      }								\
}								\
								\
void								\
test##NAME##N (struct S##NAME##N s1, struct S##NAME##N s2,	\
	       struct S##NAME##N s3, struct S##NAME##N s4,	\
	       struct S##NAME##N s5, struct S##NAME##N s6,	\
	       struct S##NAME##N s7, struct S##NAME##N s8,	\
	       struct S##NAME##N s9, struct S##NAME##N s10,	\
	       struct S##NAME##N s11, struct S##NAME##N s12,	\
	       struct S##NAME##N s13, struct S##NAME##N s14,	\
	       struct S##NAME##N s15, struct S##NAME##N s16)	\
{								\
  DEBUG_DOT;							\
  check##NAME##N (&s1, 1*16);					\
  DEBUG_DOT;							\
  check##NAME##N (&s2, 2*16);					\
  DEBUG_DOT;							\
  check##NAME##N (&s3, 3*16);					\
  DEBUG_DOT;							\
  check##NAME##N (&s4, 4*16);					\
  DEBUG_DOT;							\
  check##NAME##N (&s5, 5*16);					\
  DEBUG_DOT;							\
  check##NAME##N (&s6, 6*16);					\
  DEBUG_DOT;							\
  check##NAME##N (&s7, 7*16);					\
  DEBUG_DOT;							\
  check##NAME##N (&s8, 8*16);					\
  DEBUG_DOT;							\
  check##NAME##N (&s9, 9*16);					\
  DEBUG_DOT;							\
  check##NAME##N (&s10, 10*16);					\
  DEBUG_DOT;							\
  check##NAME##N (&s11, 11*16);					\
  DEBUG_DOT;							\
  check##NAME##N (&s12, 12*16);					\
  DEBUG_DOT;							\
  check##NAME##N (&s13, 13*16);					\
  DEBUG_DOT;							\
  check##NAME##N (&s14, 14*16);					\
  DEBUG_DOT;							\
  check##NAME##N (&s15, 15*16);					\
  DEBUG_DOT;							\
  check##NAME##N (&s16, 16*16);					\
}								\
								\
void								\
testva##NAME##N (int n, ...)					\
{								\
  int i;							\
  va_list ap;							\
  va_start (ap, n);						\
  for (i = 0; i < n; i++)					\
    {								\
      struct S##NAME##N t = va_arg (ap, struct S##NAME##N);	\
      DEBUG_DOT;						\
      check##NAME##N (&t, (i+1)*16);				\
    }								\
  va_end (ap);							\
}								\
								\
void								\
test2_##NAME##N (struct S##NAME##N s1, struct S##NAME##N s2,	\
		 struct S##NAME##N s3, struct S##NAME##N s4,	\
		 struct S##NAME##N s5, struct S##NAME##N s6,	\
		 struct S##NAME##N s7, struct S##NAME##N s8)	\
{								\
  test##NAME##N (s1, g2s##NAME##N, s2, g4s##NAME##N,		\
		 s3, g6s##NAME##N, s4, g8s##NAME##N,		\
		 s5, g10s##NAME##N, s6, g12s##NAME##N,		\
		 s7, g14s##NAME##N, s8, g16s##NAME##N);		\
}								\
								\
void								\
testit##NAME##N (void)						\
{								\
  DEBUG_FPUTS (#NAME "[" #N "]");				\
  init##NAME##N  ( &g1s##NAME##N,  1*16);			\
  init##NAME##N  ( &g2s##NAME##N,  2*16);			\
  init##NAME##N  ( &g3s##NAME##N,  3*16);			\
  init##NAME##N  ( &g4s##NAME##N,  4*16);			\
  init##NAME##N  ( &g5s##NAME##N,  5*16);			\
  init##NAME##N  ( &g6s##NAME##N,  6*16);			\
  init##NAME##N  ( &g7s##NAME##N,  7*16);			\
  init##NAME##N  ( &g8s##NAME##N,  8*16);			\
  init##NAME##N  ( &g9s##NAME##N,  9*16);			\
  init##NAME##N  (&g10s##NAME##N, 10*16);			\
  init##NAME##N  (&g11s##NAME##N, 11*16);			\
  init##NAME##N  (&g12s##NAME##N, 12*16);			\
  init##NAME##N  (&g13s##NAME##N, 13*16);			\
  init##NAME##N  (&g14s##NAME##N, 14*16);			\
  init##NAME##N  (&g15s##NAME##N, 15*16);			\
  init##NAME##N  (&g16s##NAME##N, 16*16);			\
  check##NAME##N ( &g1s##NAME##N,  1*16);			\
  check##NAME##N ( &g2s##NAME##N,  2*16);			\
  check##NAME##N ( &g3s##NAME##N,  3*16);			\
  check##NAME##N ( &g4s##NAME##N,  4*16);			\
  check##NAME##N ( &g5s##NAME##N,  5*16);			\
  check##NAME##N ( &g6s##NAME##N,  6*16);			\
  check##NAME##N ( &g7s##NAME##N,  7*16);			\
  check##NAME##N ( &g8s##NAME##N,  8*16);			\
  check##NAME##N ( &g9s##NAME##N,  9*16);			\
  check##NAME##N (&g10s##NAME##N, 10*16);			\
  check##NAME##N (&g11s##NAME##N, 11*16);			\
  check##NAME##N (&g12s##NAME##N, 12*16);			\
  check##NAME##N (&g13s##NAME##N, 13*16);			\
  check##NAME##N (&g14s##NAME##N, 14*16);			\
  check##NAME##N (&g15s##NAME##N, 15*16);			\
  check##NAME##N (&g16s##NAME##N, 16*16);			\
  DEBUG_FPUTS (" test");					\
  test##NAME##N (g1s##NAME##N, g2s##NAME##N,			\
		 g3s##NAME##N, g4s##NAME##N,			\
		 g5s##NAME##N, g6s##NAME##N,			\
		 g7s##NAME##N, g8s##NAME##N,			\
		 g9s##NAME##N, g10s##NAME##N,			\
		 g11s##NAME##N, g12s##NAME##N,			\
		 g13s##NAME##N, g14s##NAME##N,			\
		 g15s##NAME##N, g16s##NAME##N);			\
  DEBUG_FPUTS (" testva");					\
  testva##NAME##N (16,						\
		   g1s##NAME##N, g2s##NAME##N,			\
		   g3s##NAME##N, g4s##NAME##N,			\
		   g5s##NAME##N, g6s##NAME##N,			\
		   g7s##NAME##N, g8s##NAME##N,			\
		   g9s##NAME##N, g10s##NAME##N,			\
		   g11s##NAME##N, g12s##NAME##N,		\
		   g13s##NAME##N, g14s##NAME##N,		\
		   g15s##NAME##N, g16s##NAME##N);		\
  DEBUG_FPUTS (" test2");					\
  test2_##NAME##N (g1s##NAME##N, g3s##NAME##N,			\
		   g5s##NAME##N, g7s##NAME##N,			\
		   g9s##NAME##N, g11s##NAME##N,			\
		   g13s##NAME##N, g15s##NAME##N);		\
  DEBUG_NL;							\
}

extern void abort (void);
extern void exit (int);

T(0, uc, unsigned char)
T(1, uc, unsigned char)
T(2, uc, unsigned char)
T(3, uc, unsigned char)
T(4, uc, unsigned char)
T(5, uc, unsigned char)
T(6, uc, unsigned char)
T(7, uc, unsigned char)
T(8, uc, unsigned char)
T(9, uc, unsigned char)
T(10, uc, unsigned char)
T(11, uc, unsigned char)
T(12, uc, unsigned char)
T(13, uc, unsigned char)
T(14, uc, unsigned char)
T(15, uc, unsigned char)
T(0, us, unsigned short)
T(1, us, unsigned short)
T(2, us, unsigned short)
T(3, us, unsigned short)
T(4, us, unsigned short)
T(5, us, unsigned short)
T(6, us, unsigned short)
T(7, us, unsigned short)
T(8, us, unsigned short)
T(9, us, unsigned short)
T(10, us, unsigned short)
T(11, us, unsigned short)
T(12, us, unsigned short)
T(13, us, unsigned short)
T(14, us, unsigned short)
T(15, us, unsigned short)
T(0, ui, unsigned int)
T(1, ui, unsigned int)
T(2, ui, unsigned int)
T(3, ui, unsigned int)
T(4, ui, unsigned int)
T(5, ui, unsigned int)
T(6, ui, unsigned int)
T(7, ui, unsigned int)
T(8, ui, unsigned int)
T(9, ui, unsigned int)
T(10, ui, unsigned int)
T(11, ui, unsigned int)
T(12, ui, unsigned int)
T(13, ui, unsigned int)
T(14, ui, unsigned int)
T(15, ui, unsigned int)

#undef T

int
main ()
{
#define T(N, NAME, TYPE) testit##NAME##N ();

T(0, uc, unsigned char)
T(1, uc, unsigned char)
T(2, uc, unsigned char)
T(3, uc, unsigned char)
T(4, uc, unsigned char)
T(5, uc, unsigned char)
T(6, uc, unsigned char)
T(7, uc, unsigned char)
T(8, uc, unsigned char)
T(9, uc, unsigned char)
T(10, uc, unsigned char)
T(11, uc, unsigned char)
T(12, uc, unsigned char)
T(13, uc, unsigned char)
T(14, uc, unsigned char)
T(15, uc, unsigned char)
T(0, us, unsigned short)
T(1, us, unsigned short)
T(2, us, unsigned short)
T(3, us, unsigned short)
T(4, us, unsigned short)
T(5, us, unsigned short)
T(6, us, unsigned short)
T(7, us, unsigned short)
T(8, us, unsigned short)
T(9, us, unsigned short)
T(10, us, unsigned short)
T(11, us, unsigned short)
T(12, us, unsigned short)
T(13, us, unsigned short)
T(14, us, unsigned short)
T(15, us, unsigned short)
T(0, ui, unsigned int)
T(1, ui, unsigned int)
T(2, ui, unsigned int)
T(3, ui, unsigned int)
T(4, ui, unsigned int)
T(5, ui, unsigned int)
T(6, ui, unsigned int)
T(7, ui, unsigned int)
T(8, ui, unsigned int)
T(9, ui, unsigned int)
T(10, ui, unsigned int)
T(11, ui, unsigned int)
T(12, ui, unsigned int)
T(13, ui, unsigned int)
T(14, ui, unsigned int)
T(15, ui, unsigned int)

#undef T
  exit (0);
}


                 reply	other threads:[~2003-04-14  9:36 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20030414092647.7407.qmail@sources.redhat.com \
    --to=amodra@bigpond.net.au \
    --cc=gcc-gnats@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).