public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
From: exco@ligim.univ-lyon1.fr
To: gcc-gnats@gcc.gnu.org
Subject: c/2588: Bad alignment when passing structure by value to function
Date: Thu, 19 Apr 2001 06:16:00 -0000	[thread overview]
Message-ID: <20010419131535.30051.qmail@sourceware.cygnus.com> (raw)

>Number:         2588
>Category:       c
>Synopsis:       Bad alignment when passing structure by value to function
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          wrong-code
>Submitter-Id:   net
>Arrival-Date:   Thu Apr 19 06:16:01 PDT 2001
>Closed-Date:
>Last-Modified:
>Originator:     Thierry EXCOFFIER
>Release:        gcc version 2.95.3 20010315 (release)
>Organization:
>Environment:
IRIX b710sibn 6.5 01101246 IP32
>Description:
For some structure size, when the structure is
passed by value to a function, its content is incorrect.

>How-To-Repeat:
/* The problem always appear when size D+F > 16 and F odd */

#define D 14
#define F 3

typedef struct
{
  int a[D] ;
} DoubleAlignment ;

typedef struct
{
  int a[F] ;
} FloatAlignment ;

void display(FloatAlignment x, DoubleAlignment y)
{
  int i ;
  
  for(i=0;i<F;i++)
    if ( x.a[i] != 100+i )
      printf("ERROR : x.a[%d] = %d != %d\n", i, x.a[i], 100+i) ;
  for(i=0;i<D;i++)
    if ( y.a[i] != 200+i )
      printf("ERROR : y.a[%d] = %d != %d\n", i, y.a[i], 200+i) ;
}

int main()
{
  FloatAlignment x ;
  DoubleAlignment y ;
  int i ;
  
  printf("D=%d F=%d\n", D, F) ;

  for(i=0;i<F;i++)
      x.a[i] = 100+i ;
  for(i=0;i<D;i++)
      y.a[i] = 200+i ;

  display(x, y) ;
  return(0) ;
}
>Fix:
Use -O3 option when compiling.
>Release-Note:
>Audit-Trail:
>Unformatted:


                 reply	other threads:[~2001-04-19  6:16 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=20010419131535.30051.qmail@sourceware.cygnus.com \
    --to=exco@ligim.univ-lyon1.fr \
    --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).