public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/11885] New: Problem with bitfields in packed structs
@ 2003-08-11 21:09 stanrost at lcs dot mit dot edu
  2003-08-11 21:14 ` [Bug c/11885] [3.3 Regression] " pinskia at gcc dot gnu dot org
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: stanrost at lcs dot mit dot edu @ 2003-08-11 21:09 UTC (permalink / raw)
  To: gcc-bugs

PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.

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

           Summary: Problem with bitfields in packed structs
           Product: gcc
           Version: 3.3.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: stanrost at lcs dot mit dot edu
                CC: gcc-bugs at gcc dot gnu dot org
  GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu avr-unknown-unknown

Hi,

I have been hacking for Berkley Motes using nesC, which produces code later
compiled by AVR-GCC.  There is a problem with bitfields within packed
structures, which is also reproducible on the native platform (i686-pc-linux-gnu).

The bug is illustrated by the following simple program:
--------------------------------------------------------------

include <stdio.h>
#include <stdint.h>

typedef struct {
    
    uint8_t flag1:2;
    uint8_t flag2:1;
    uint8_t flag3:1;
   
    uint8_t flag4;

} __attribute__ ((packed)) MyType;

int main(void) {

    MyType a;
    MyType *b = &a;

    b->flag1 = 0;
    b->flag2 = 0;
    b->flag3 = 0;

    b->flag4 = 0;

    b->flag4++;
    
    if (b->flag1)
	printf("Set\n");
    else
	printf("Clear\n");

}

--------------------------------------------------------------

This is clearly an error because flag4 should be allocated its own byte
and not packed into the byte with other variables.

Please look into this, as the current methods of circumvention force me
to pad the structures with "reserved" bitfields.

Respectfully,

Stan Rost


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

* [Bug c/11885] [3.3 Regression] Problem with bitfields in packed structs
  2003-08-11 21:09 [Bug c/11885] New: Problem with bitfields in packed structs stanrost at lcs dot mit dot edu
@ 2003-08-11 21:14 ` pinskia at gcc dot gnu dot org
  2003-08-11 21:21 ` pinskia at gcc dot gnu dot org
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2003-08-11 21:14 UTC (permalink / raw)
  To: gcc-bugs

PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.

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


pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |critical
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|                            |1
           Keywords|                            |wrong-code
           Priority|P2                          |P1
   Last reconfirmed|0000-00-00 00:00:00         |2003-08-11 21:14:39
               date|                            |
            Summary|Problem with bitfields in   |[3.3 Regression] Problem
                   |packed structs              |with bitfields in packed
                   |                            |structs
   Target Milestone|3.4                         |3.3.2


------- Additional Comments From pinskia at gcc dot gnu dot org  2003-08-11 21:14 -------
I can reproduce this in 3.3.1 (20030707).  It is already fixed on the mainline and also in 3.2.3 so 
making this a regression.


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

* [Bug c/11885] [3.3 Regression] Problem with bitfields in packed structs
  2003-08-11 21:09 [Bug c/11885] New: Problem with bitfields in packed structs stanrost at lcs dot mit dot edu
  2003-08-11 21:14 ` [Bug c/11885] [3.3 Regression] " pinskia at gcc dot gnu dot org
@ 2003-08-11 21:21 ` pinskia at gcc dot gnu dot org
  2003-08-11 23:27 ` stanrost at lcs dot mit dot edu
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2003-08-11 21:21 UTC (permalink / raw)
  To: gcc-bugs

PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.

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



------- Additional Comments From pinskia at gcc dot gnu dot org  2003-08-11 21:21 -------
Can you try the patch in PR 11662?
<http://gcc.gnu.org/bugzilla/attachment.cgi?id=4479&action=view>


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

* [Bug c/11885] [3.3 Regression] Problem with bitfields in packed structs
  2003-08-11 21:09 [Bug c/11885] New: Problem with bitfields in packed structs stanrost at lcs dot mit dot edu
  2003-08-11 21:14 ` [Bug c/11885] [3.3 Regression] " pinskia at gcc dot gnu dot org
  2003-08-11 21:21 ` pinskia at gcc dot gnu dot org
@ 2003-08-11 23:27 ` stanrost at lcs dot mit dot edu
  2003-08-11 23:40 ` pinskia at gcc dot gnu dot org
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: stanrost at lcs dot mit dot edu @ 2003-08-11 23:27 UTC (permalink / raw)
  To: gcc-bugs

PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.

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



------- Additional Comments From stanrost at lcs dot mit dot edu  2003-08-11 23:27 -------
Just tried the patch, recompiled and reinstalled, but the patch
you suggested did not fix the problem.

Additionally, I double-checked everything so that the last sentence
is not in error.


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

* [Bug c/11885] [3.3 Regression] Problem with bitfields in packed structs
  2003-08-11 21:09 [Bug c/11885] New: Problem with bitfields in packed structs stanrost at lcs dot mit dot edu
                   ` (2 preceding siblings ...)
  2003-08-11 23:27 ` stanrost at lcs dot mit dot edu
@ 2003-08-11 23:40 ` pinskia at gcc dot gnu dot org
  2003-08-12  0:02 ` janis187 at us dot ibm dot com
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2003-08-11 23:40 UTC (permalink / raw)
  To: gcc-bugs

PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.

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


pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |janis187 at us dot ibm dot
                   |                            |com


------- Additional Comments From pinskia at gcc dot gnu dot org  2003-08-11 23:40 -------
Thanks for trying this patch, this helps us figure out which patch fixes this on the mainline.
Janis,
 can you run your regression finder on this one as it looks like a bad regression (which is already 
fixed on the mainline) as prevents any one to use reserved fields in packed structors with bitfields.


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

* [Bug c/11885] [3.3 Regression] Problem with bitfields in packed structs
  2003-08-11 21:09 [Bug c/11885] New: Problem with bitfields in packed structs stanrost at lcs dot mit dot edu
                   ` (3 preceding siblings ...)
  2003-08-11 23:40 ` pinskia at gcc dot gnu dot org
@ 2003-08-12  0:02 ` janis187 at us dot ibm dot com
  2003-08-12 16:51 ` janis187 at us dot ibm dot com
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: janis187 at us dot ibm dot com @ 2003-08-12  0:02 UTC (permalink / raw)
  To: gcc-bugs

PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.

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



------- Additional Comments From janis187 at us dot ibm dot com  2003-08-12 00:02 -------
Subject: Re:  [3.3 Regression] Problem with bitfields in packed structs

This looked like an interesting bug so I started a hunt on the 3.3
branch a couple of hours ago, and it's now down to a single day
(2003-03-31).  When I identify where it broke on the branch I'll
check to see if it was also broken on mainline, and then what fixed
it on mainline.


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

* [Bug c/11885] [3.3 Regression] Problem with bitfields in packed structs
  2003-08-11 21:09 [Bug c/11885] New: Problem with bitfields in packed structs stanrost at lcs dot mit dot edu
                   ` (4 preceding siblings ...)
  2003-08-12  0:02 ` janis187 at us dot ibm dot com
@ 2003-08-12 16:51 ` janis187 at us dot ibm dot com
  2003-08-29 21:16 ` jason at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: janis187 at us dot ibm dot com @ 2003-08-12 16:51 UTC (permalink / raw)
  To: gcc-bugs

PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.

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


janis187 at us dot ibm dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jason at redhat dot com


------- Additional Comments From janis187 at us dot ibm dot com  2003-08-12 16:51 -------
The regression in PR 11885 was introduced or exposed on the 3.3 branch
and mainline by this patch:

--- gcc/gcc/ChangeLog ---

2003-03-31  Jason Merrill  <jason@redhat.com>

        * stor-layout.c (update_alignment_for_field): Respect
        DECL_USER_ALIGN for zero-length bitfields, too.
        * c-decl.c (finish_struct): Don't set DECL_ALIGN for normal
        fields.

--- gcc/gcc/cp/ChangeLog ---

2003-03-31  Jason Merrill  <jason@redhat.com>

        * class.c (check_field_decl): Don't set DECL_ALIGN.

The test case passes for mainline after this large patch:

--- gcc/gcc/ChangeLog ---

2003-04-03  Jason Merrill  <jason@redhat.com>

        * stor-layout.c (do_type_align): New fn, split out from...
        (layout_decl): ...here.  Do all alignment calculations for
        FIELD_DECLs here.
        (update_alignment_for_field): Not here.
        (start_record_layout, debug_rli): Remove unpadded_align.
        * tree.h (struct record_layout_info_s): Remove unpadded_align.
        * c-decl.c (finish_enum): Don't set DECL_SIZE, DECL_ALIGN
        or DECL_MODE on the CONST_DECLs.
        (finish_struct): Don't mess with DECL_ALIGN.

--- gcc/gcc/cp/ChangeLog ---

2003-04-03  Jason Merrill  <jason@redhat.com>

        * class.c (build_vtable): Set DECL_ALIGN here.
        (get_vtable_decl): Not here.
        (layout_vtable_decl): Or here.
        (create_vtable_ptr): Or here.
        (layout_class_type): Or here.
        (check_bitfield_decl): Don't mess with field alignment.

The hunts took place on i686-pc-linux-gnu using the submitter's test case.


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

* [Bug c/11885] [3.3 Regression] Problem with bitfields in packed structs
  2003-08-11 21:09 [Bug c/11885] New: Problem with bitfields in packed structs stanrost at lcs dot mit dot edu
                   ` (5 preceding siblings ...)
  2003-08-12 16:51 ` janis187 at us dot ibm dot com
@ 2003-08-29 21:16 ` jason at gcc dot gnu dot org
  2003-10-14 18:43 ` cvs-commit at gcc dot gnu dot org
  2003-10-14 18:51 ` pinskia at gcc dot gnu dot org
  8 siblings, 0 replies; 10+ messages in thread
From: jason at gcc dot gnu dot org @ 2003-08-29 21:16 UTC (permalink / raw)
  To: gcc-bugs

PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.

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


jason at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|unassigned at gcc dot gnu   |jason at redhat dot com
                   |dot org                     |
             Status|NEW                         |ASSIGNED


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

* [Bug c/11885] [3.3 Regression] Problem with bitfields in packed structs
  2003-08-11 21:09 [Bug c/11885] New: Problem with bitfields in packed structs stanrost at lcs dot mit dot edu
                   ` (6 preceding siblings ...)
  2003-08-29 21:16 ` jason at gcc dot gnu dot org
@ 2003-10-14 18:43 ` cvs-commit at gcc dot gnu dot org
  2003-10-14 18:51 ` pinskia at gcc dot gnu dot org
  8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu dot org @ 2003-10-14 18:43 UTC (permalink / raw)
  To: gcc-bugs

PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.

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



------- Additional Comments From cvs-commit at gcc dot gnu dot org  2003-10-14 18:43 -------
Subject: Bug 11885

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-3_3-branch
Changes by:	jason@gcc.gnu.org	2003-10-14 18:43:09

Modified files:
	gcc            : ChangeLog stor-layout.c 

Log message:
	PR c/11885
	* stor-layout.c (update_alignment_for_field): Packed non-bit-fields
	get byte alignment.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.16114.2.780&r2=1.16114.2.781
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/stor-layout.c.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.134.2.4&r2=1.134.2.5


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

* [Bug c/11885] [3.3 Regression] Problem with bitfields in packed structs
  2003-08-11 21:09 [Bug c/11885] New: Problem with bitfields in packed structs stanrost at lcs dot mit dot edu
                   ` (7 preceding siblings ...)
  2003-10-14 18:43 ` cvs-commit at gcc dot gnu dot org
@ 2003-10-14 18:51 ` pinskia at gcc dot gnu dot org
  8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2003-10-14 18:51 UTC (permalink / raw)
  To: gcc-bugs

PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.

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


pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |FIXED


------- Additional Comments From pinskia at gcc dot gnu dot org  2003-10-14 18:51 -------
Fixed for 3.3.2.


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

end of thread, other threads:[~2003-10-14 18:51 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-08-11 21:09 [Bug c/11885] New: Problem with bitfields in packed structs stanrost at lcs dot mit dot edu
2003-08-11 21:14 ` [Bug c/11885] [3.3 Regression] " pinskia at gcc dot gnu dot org
2003-08-11 21:21 ` pinskia at gcc dot gnu dot org
2003-08-11 23:27 ` stanrost at lcs dot mit dot edu
2003-08-11 23:40 ` pinskia at gcc dot gnu dot org
2003-08-12  0:02 ` janis187 at us dot ibm dot com
2003-08-12 16:51 ` janis187 at us dot ibm dot com
2003-08-29 21:16 ` jason at gcc dot gnu dot org
2003-10-14 18:43 ` cvs-commit at gcc dot gnu dot org
2003-10-14 18:51 ` pinskia 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).