public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "ianw at gelato dot unsw dot edu dot au" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c/22605] New: Allocation of structures across stack slots
Date: Fri, 22 Jul 2005 05:45:00 -0000	[thread overview]
Message-ID: <20050722045450.22605.ianw@gelato.unsw.edu.au> (raw)

Hi,

gcc 4 seems quite a bit smarter at keeping the stack smaller, and as you can see
below allocates the 8 byte structure across two stack slots.

It did break something, which drew this to my attention, and James Wilson
already some analsysis in
http://www.gelato.unsw.edu.au/archives/linux-ia64/0507/1885.html.  Quoting him

 > If gcc-3.4 and earlier, some structures (BLKmode structures) were being
 > over-aligned when allocated to stack slots.  They always got the maximum
 > alignment (16 bytes for IA-64) instead of their natural alignment.  It
 > isn't clear why.  I think this was an accident of implementation.  We
 > were basing variable alignment on modes instead of type alignment, and
 > since some BLKmode structures do require max alignment, we had to give
 > it to all of them.

We came to the conclusion that we are unsure if this is a bug or a feature.  I
am unsure if the larger stack space required is a good trade off against
possible better code.

Thanks,

-i

--- sample ---

ianw@lime:/tmp$ cat test.c
#include <stdio.h>

struct disk_stat {
        int fd;
        unsigned count;
};

int main(void)
{
        int blah;
        struct disk_stat test;

        printf("%p\n", &blah);

        printf("%p\n", &test);
}
ianw@lime:/tmp$ gcc-3.4 -o test test.c
ianw@lime:/tmp$ ./test
0x60000fffffcdf480
0x60000fffffcdf490

ianw@lime:/tmp$ gcc-4.0 -o test test.c
ianw@lime:/tmp$ ./test
0x60000fffffd57490
0x60000fffffd57494

-- 
           Summary: Allocation of structures across stack slots
           Product: gcc
           Version: 4.0.1
            Status: UNCONFIRMED
          Severity: minor
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: ianw at gelato dot unsw dot edu dot au
                CC: gcc-bugs at gcc dot gnu dot org
GCC target triplet: ia64-linux-gnu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=22605


             reply	other threads:[~2005-07-22  4:54 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-07-22  5:45 ianw at gelato dot unsw dot edu dot au [this message]
2005-07-22 18:12 ` [Bug middle-end/22605] Alignment of struct on stack is no longer the maxium alignment pinskia at gcc dot gnu dot org
2005-07-22 20:15 ` wilson at gcc dot gnu dot org

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=20050722045450.22605.ianw@gelato.unsw.edu.au \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@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).