public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/27945]  New: Packed struct of variable length has wrong size
@ 2006-06-08  2:33 alpt at freaknet dot org
  2006-06-08  2:48 ` [Bug c/27945] " alpt at freaknet dot org
                   ` (12 more replies)
  0 siblings, 13 replies; 14+ messages in thread
From: alpt at freaknet dot org @ 2006-06-08  2:33 UTC (permalink / raw)
  To: gcc-bugs

Consider this test: http://hinezumilabs.org/alpt/test-pack.c

#define _PACKED_ __attribute__ ((__packed__))
int func(int levels) 
{
        struct foo {
                u_char          a;
                int32_t         b[levels];
                struct timeval _PACKED_ c[levels];
                u_int           d[4];
        }_PACKED_ pkt;

        struct bar {
                u_char          a;
                int32_t         b[levels];
                struct timeval  c[levels];
                u_int           d[4];
        }_PACKED_ pktII;

        printf("pkt %d, foo %d\n", sizeof(pkt), sizeof(struct foo));
        printf("pktII %d, bar %d\n", sizeof(pktII), sizeof(struct bar));
}

On a x86 with gcc-3.4.x/3.3.6 it prints:
pkt 65, foo 65
pktII 65, bar 65
(this is the right output)

while compiled for mips and runned on a BCM3302 (mips) with a gcc-3.4.4
it gives:
pkt 68, foo 68
pktII 68, bar 68

On a gentoo's 4.1.1 amd64:
pkt 104, foo 104
pktII 104, bar 104

On a x86 with the same version of gcc:
pkt 68, foo 68
pktII 68, bar 68

That's all ;)


-- 
           Summary: Packed struct of variable length has wrong size
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: alpt at freaknet dot org


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


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [Bug c/27945] Packed struct of variable length has wrong size
  2006-06-08  2:33 [Bug c/27945] New: Packed struct of variable length has wrong size alpt at freaknet dot org
@ 2006-06-08  2:48 ` alpt at freaknet dot org
  2006-06-08  3:10 ` pinskia at gcc dot gnu dot org
                   ` (11 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: alpt at freaknet dot org @ 2006-06-08  2:48 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from alpt at freaknet dot org  2006-06-08 02:33 -------
On gcc 4.0.2, PIII:
pkt 68, foo 68
pktII 68, bar 68


-- 

alpt at freaknet dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |alpt at freaknet dot org


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


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [Bug c/27945] Packed struct of variable length has wrong size
  2006-06-08  2:33 [Bug c/27945] New: Packed struct of variable length has wrong size alpt at freaknet dot org
  2006-06-08  2:48 ` [Bug c/27945] " alpt at freaknet dot org
@ 2006-06-08  3:10 ` pinskia at gcc dot gnu dot org
  2006-06-08  4:52 ` alpt at freaknet dot org
                   ` (10 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2006-06-08  3:10 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from pinskia at gcc dot gnu dot org  2006-06-08 03:00 -------
> On a x86 with gcc-3.4.x/3.3.6 it prints:
> pkt 65, foo 65
> pktII 65, bar 65
> (this is the right output)

I don't get 65 with 3.4.0, I get 68 like 4.0.0 and above.
earth:~>~/ia32_linux_gcc3_4/bin/gcc -O2 t.c
earth:~>./a.out
pkt 68, foo 68
pktII 68, bar 68
earth:~>~/ia32_linux_gcc3_3/bin/gcc -O2 t.c
earth:~>./a.out
pkt 65, foo 65
pktII 65, bar 65

You should note this is extension even on top of C99 so it might be correct to
change it.


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |ABI


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


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [Bug c/27945] Packed struct of variable length has wrong size
  2006-06-08  2:33 [Bug c/27945] New: Packed struct of variable length has wrong size alpt at freaknet dot org
  2006-06-08  2:48 ` [Bug c/27945] " alpt at freaknet dot org
  2006-06-08  3:10 ` pinskia at gcc dot gnu dot org
@ 2006-06-08  4:52 ` alpt at freaknet dot org
  2006-06-09  7:48 ` [Bug middle-end/27945] [4.0/4.1/4.2 Regression] " pinskia at gcc dot gnu dot org
                   ` (9 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: alpt at freaknet dot org @ 2006-06-08  4:52 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from alpt at freaknet dot org  2006-06-08 03:14 -------
You're right. on 3.4.x I get wrong results too.

The only positive result I get is on 3.3.6.

~> You should note this is extension even on top of C99 so it might be correct
~> to change it.

Yep, but it is a very elegant extension ;)


-- 


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


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [Bug middle-end/27945] [4.0/4.1/4.2 Regression] Packed struct of variable length has wrong size
  2006-06-08  2:33 [Bug c/27945] New: Packed struct of variable length has wrong size alpt at freaknet dot org
                   ` (2 preceding siblings ...)
  2006-06-08  4:52 ` alpt at freaknet dot org
@ 2006-06-09  7:48 ` pinskia at gcc dot gnu dot org
  2006-07-05 17:59 ` mmitchel at gcc dot gnu dot org
                   ` (8 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2006-06-09  7:48 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from pinskia at gcc dot gnu dot org  2006-06-09 07:45 -------
Confirmed.


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
          Component|c                           |middle-end
     Ever Confirmed|0                           |1
      Known to fail|                            |3.4.0 4.0.0 4.1.0 4.2.0
      Known to work|                            |3.3.3
   Last reconfirmed|0000-00-00 00:00:00         |2006-06-09 07:45:54
               date|                            |
            Summary|Packed struct of variable   |[4.0/4.1/4.2 Regression]
                   |length has wrong size       |Packed struct of variable
                   |                            |length has wrong size
   Target Milestone|---                         |4.0.4


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


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [Bug middle-end/27945] [4.0/4.1/4.2 Regression] Packed struct of variable length has wrong size
  2006-06-08  2:33 [Bug c/27945] New: Packed struct of variable length has wrong size alpt at freaknet dot org
                   ` (3 preceding siblings ...)
  2006-06-09  7:48 ` [Bug middle-end/27945] [4.0/4.1/4.2 Regression] " pinskia at gcc dot gnu dot org
@ 2006-07-05 17:59 ` mmitchel at gcc dot gnu dot org
  2006-08-08 16:05 ` janis at gcc dot gnu dot org
                   ` (7 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: mmitchel at gcc dot gnu dot org @ 2006-07-05 17:59 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from mmitchel at gcc dot gnu dot org  2006-07-05 17:59 -------
We should understand if there was an intentional ABI change.


-- 

mmitchel at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P3                          |P1


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


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [Bug middle-end/27945] [4.0/4.1/4.2 Regression] Packed struct of variable length has wrong size
  2006-06-08  2:33 [Bug c/27945] New: Packed struct of variable length has wrong size alpt at freaknet dot org
                   ` (4 preceding siblings ...)
  2006-07-05 17:59 ` mmitchel at gcc dot gnu dot org
@ 2006-08-08 16:05 ` janis at gcc dot gnu dot org
  2006-08-25 19:31 ` kazu at gcc dot gnu dot org
                   ` (6 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: janis at gcc dot gnu dot org @ 2006-08-08 16:05 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from janis at gcc dot gnu dot org  2006-08-08 16:05 -------
A regression hunt on powerpc-linux showed that the behavior changed with this
patch:

    http://gcc.gnu.org/viewcvs?view=rev&rev=65103

    r65103 | jason | 2003-03-31 20:25:11 +0000 (Mon, 31 Mar 2003)

There was discussion on the mailing list about this, referenced from
http://gcc.gnu.org/ml/gcc-patches/2003-03/msg02550.html.


-- 

janis at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jason at gcc dot gnu dot org


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


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [Bug middle-end/27945] [4.0/4.1/4.2 Regression] Packed struct of variable length has wrong size
  2006-06-08  2:33 [Bug c/27945] New: Packed struct of variable length has wrong size alpt at freaknet dot org
                   ` (5 preceding siblings ...)
  2006-08-08 16:05 ` janis at gcc dot gnu dot org
@ 2006-08-25 19:31 ` kazu at gcc dot gnu dot org
  2006-09-23 21:59 ` kazu at gcc dot gnu dot org
                   ` (5 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: kazu at gcc dot gnu dot org @ 2006-08-25 19:31 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #7 from kazu at gcc dot gnu dot org  2006-08-25 19:31 -------
Reproduced.  Looking at this now.


-- 

kazu at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|unassigned at gcc dot gnu   |kazu at gcc dot gnu dot org
                   |dot org                     |
             Status|NEW                         |ASSIGNED


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


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [Bug middle-end/27945] [4.0/4.1/4.2 Regression] Packed struct of variable length has wrong size
  2006-06-08  2:33 [Bug c/27945] New: Packed struct of variable length has wrong size alpt at freaknet dot org
                   ` (6 preceding siblings ...)
  2006-08-25 19:31 ` kazu at gcc dot gnu dot org
@ 2006-09-23 21:59 ` kazu at gcc dot gnu dot org
  2006-11-14  1:10 ` [Bug middle-end/27945] [4.0/4.1/4.2/4.3 " jason at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: kazu at gcc dot gnu dot org @ 2006-09-23 21:59 UTC (permalink / raw)
  To: gcc-bugs



-- 

kazu at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|kazu at gcc dot gnu dot org |unassigned at gcc dot gnu
                   |                            |dot org
             Status|ASSIGNED                    |NEW


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


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [Bug middle-end/27945] [4.0/4.1/4.2/4.3 Regression] Packed struct of variable length has wrong size
  2006-06-08  2:33 [Bug c/27945] New: Packed struct of variable length has wrong size alpt at freaknet dot org
                   ` (7 preceding siblings ...)
  2006-09-23 21:59 ` kazu at gcc dot gnu dot org
@ 2006-11-14  1:10 ` jason at gcc dot gnu dot org
  2007-02-03 17:34 ` gdr at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: jason at gcc dot gnu dot org @ 2006-11-14  1:10 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #8 from jason at gcc dot gnu dot org  2006-11-14 01:10 -------
Ah, I see the problem.  The code I removed from the C and C++ front ends was
redundant with code in layout_decl, except that the code in layout_decl
deliberately ignores DECL_PACKED for fields of variable size.

      /* If the field is of variable size, we can't misalign it since we        
         have no way to make a temporary to align the result.  But this         
         isn't an issue if the decl is not addressable.  Likewise if it         
         is of unknown size.                                                    

         Note that do_type_align may set DECL_USER_ALIGN, so we need to         
         check old_user_align instead.  */
=>    if (packed_p
          && !old_user_align
          && (DECL_NONADDRESSABLE_P (decl)
              || DECL_SIZE_UNIT (decl) == 0
              || TREE_CODE (DECL_SIZE_UNIT (decl)) == INTEGER_CST))
        DECL_ALIGN (decl) = MIN (DECL_ALIGN (decl), BITS_PER_UNIT);

This dates back to a change of Kenner's from 2001:

Sat Dec 29 15:48:54 2001  Richard Kenner  <kenner@vlsi1.ultra.nyu.edu>

        * stor-layout.c (layout_decl): Don't misalign field of variable size
        for packed record.

Richard, do you have any input?  Do you think there a way to make that test
more specific to the case were fixing?


-- 

jason at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |kenner at vlsi1 dot ultra
                   |                            |dot nyu dot edu
         AssignedTo|unassigned at gcc dot gnu   |jason at gcc dot gnu dot org
                   |dot org                     |
             Status|NEW                         |ASSIGNED
   Last reconfirmed|2006-06-09 07:45:54         |2006-11-14 01:10:19
               date|                            |


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


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [Bug middle-end/27945] [4.0/4.1/4.2/4.3 Regression] Packed struct of variable length has wrong size
  2006-06-08  2:33 [Bug c/27945] New: Packed struct of variable length has wrong size alpt at freaknet dot org
                   ` (8 preceding siblings ...)
  2006-11-14  1:10 ` [Bug middle-end/27945] [4.0/4.1/4.2/4.3 " jason at gcc dot gnu dot org
@ 2007-02-03 17:34 ` gdr at gcc dot gnu dot org
  2007-02-03 20:35 ` pinskia at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: gdr at gcc dot gnu dot org @ 2007-02-03 17:34 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #9 from gdr at gcc dot gnu dot org  2007-02-03 17:34 -------
Won't fix in GCC-4.0.x.  Adjusting milestone.


-- 

gdr at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|4.0.4                       |4.1.3


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


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [Bug middle-end/27945] [4.0/4.1/4.2/4.3 Regression] Packed struct of variable length has wrong size
  2006-06-08  2:33 [Bug c/27945] New: Packed struct of variable length has wrong size alpt at freaknet dot org
                   ` (9 preceding siblings ...)
  2007-02-03 17:34 ` gdr at gcc dot gnu dot org
@ 2007-02-03 20:35 ` pinskia at gcc dot gnu dot org
  2007-02-14  9:01 ` mmitchel at gcc dot gnu dot org
  2007-09-24 21:01 ` jason at gcc dot gnu dot org
  12 siblings, 0 replies; 14+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2007-02-03 20:35 UTC (permalink / raw)
  To: gcc-bugs



-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|4.1.3                       |4.1.2


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


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [Bug middle-end/27945] [4.0/4.1/4.2/4.3 Regression] Packed struct of variable length has wrong size
  2006-06-08  2:33 [Bug c/27945] New: Packed struct of variable length has wrong size alpt at freaknet dot org
                   ` (10 preceding siblings ...)
  2007-02-03 20:35 ` pinskia at gcc dot gnu dot org
@ 2007-02-14  9:01 ` mmitchel at gcc dot gnu dot org
  2007-09-24 21:01 ` jason at gcc dot gnu dot org
  12 siblings, 0 replies; 14+ messages in thread
From: mmitchel at gcc dot gnu dot org @ 2007-02-14  9:01 UTC (permalink / raw)
  To: gcc-bugs



-- 

mmitchel at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|4.1.2                       |4.1.3


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


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [Bug middle-end/27945] [4.0/4.1/4.2/4.3 Regression] Packed struct of variable length has wrong size
  2006-06-08  2:33 [Bug c/27945] New: Packed struct of variable length has wrong size alpt at freaknet dot org
                   ` (11 preceding siblings ...)
  2007-02-14  9:01 ` mmitchel at gcc dot gnu dot org
@ 2007-09-24 21:01 ` jason at gcc dot gnu dot org
  12 siblings, 0 replies; 14+ messages in thread
From: jason at gcc dot gnu dot org @ 2007-09-24 21:01 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #10 from jason at gcc dot gnu dot org  2007-09-24 21:00 -------
Fixed in 4.3.0.  Not sure if the fix should go into 4.2.x, since it's an ABI
change.


-- 

jason at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
      Known to work|3.3.3                       |3.3.3 4.3.0
         Resolution|                            |FIXED


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


^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2007-09-24 21:01 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-06-08  2:33 [Bug c/27945] New: Packed struct of variable length has wrong size alpt at freaknet dot org
2006-06-08  2:48 ` [Bug c/27945] " alpt at freaknet dot org
2006-06-08  3:10 ` pinskia at gcc dot gnu dot org
2006-06-08  4:52 ` alpt at freaknet dot org
2006-06-09  7:48 ` [Bug middle-end/27945] [4.0/4.1/4.2 Regression] " pinskia at gcc dot gnu dot org
2006-07-05 17:59 ` mmitchel at gcc dot gnu dot org
2006-08-08 16:05 ` janis at gcc dot gnu dot org
2006-08-25 19:31 ` kazu at gcc dot gnu dot org
2006-09-23 21:59 ` kazu at gcc dot gnu dot org
2006-11-14  1:10 ` [Bug middle-end/27945] [4.0/4.1/4.2/4.3 " jason at gcc dot gnu dot org
2007-02-03 17:34 ` gdr at gcc dot gnu dot org
2007-02-03 20:35 ` pinskia at gcc dot gnu dot org
2007-02-14  9:01 ` mmitchel at gcc dot gnu dot org
2007-09-24 21:01 ` jason at gcc dot gnu dot org

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).