public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/41788]  New: -Wpacked option changes the layout of packed non-POD structs
@ 2009-10-22  0:05 nenad at tensilica dot com
  2009-10-22  9:32 ` [Bug c++/41788] " rguenth at gcc dot gnu dot org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: nenad at tensilica dot com @ 2009-10-22  0:05 UTC (permalink / raw)
  To: gcc-bugs

When a packed non-POD struct is included in another packed struct,
the outer struct layout changes depending on whether -Wpacked is used or not.
It seems wrong that a warning option affects data layout and code generation.

The same behavior is observed with 4.4.2, 4.3.4, 4.2.1, 4.1.2.
It could be related to bug 26670.

% cat packed_nonpod.cpp

extern "C" int printf (__const char *__restrict __format, ...);

struct INNER {
  virtual int foo() const { return 1; }
} __attribute__ ((packed));

struct OUTER {
  char c;
  INNER inner;
} __attribute__ ((packed));

int main()
{
  OUTER outer;
  printf("sizeof(outer) = %u\n", sizeof(outer));
  printf("offset(inner) = %u\n", (char *)&outer.inner - (char *)&outer);
  return 0;
}

% g++ packed_nonpod.cpp
% a.out
sizeof(outer) = 5
offset(inner) = 1

% g++ packed_nonpod.cpp -Wpacked
packed_nonpod.cpp:3: warning: packed attribute is unnecessary for 'INNER'
packed_nonpod.cpp:9: warning: ignoring packed attribute because of unpacked
non-POD field 'INNER OUTER::inner'
% a.out
sizeof(outer) = 8
offset(inner) = 4


-- 
           Summary: -Wpacked option changes the layout of packed non-POD
                    structs
           Product: gcc
           Version: 4.4.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: nenad at tensilica dot com
 GCC build triplet: i686-pc-linux-gnu
  GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu


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


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

* [Bug c++/41788] -Wpacked option changes the layout of packed non-POD structs
  2009-10-22  0:05 [Bug c++/41788] New: -Wpacked option changes the layout of packed non-POD structs nenad at tensilica dot com
@ 2009-10-22  9:32 ` rguenth at gcc dot gnu dot org
  2009-10-22 16:23 ` nenad at tensilica dot com
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2009-10-22  9:32 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from rguenth at gcc dot gnu dot org  2009-10-22 09:32 -------
Confirmed.


-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|0                           |1
           Keywords|                            |diagnostic, wrong-code
   Last reconfirmed|0000-00-00 00:00:00         |2009-10-22 09:32:15
               date|                            |


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


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

* [Bug c++/41788] -Wpacked option changes the layout of packed non-POD structs
  2009-10-22  0:05 [Bug c++/41788] New: -Wpacked option changes the layout of packed non-POD structs nenad at tensilica dot com
  2009-10-22  9:32 ` [Bug c++/41788] " rguenth at gcc dot gnu dot org
@ 2009-10-22 16:23 ` nenad at tensilica dot com
  2010-01-20 21:47 ` jason at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: nenad at tensilica dot com @ 2009-10-22 16:23 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from nenad at tensilica dot com  2009-10-22 16:22 -------
By the way, if comment #7 from bug 26670 still applies,
then the code is correct with -Wpacked, and wrong without it.


-- 


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


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

* [Bug c++/41788] -Wpacked option changes the layout of packed non-POD structs
  2009-10-22  0:05 [Bug c++/41788] New: -Wpacked option changes the layout of packed non-POD structs nenad at tensilica dot com
  2009-10-22  9:32 ` [Bug c++/41788] " rguenth at gcc dot gnu dot org
  2009-10-22 16:23 ` nenad at tensilica dot com
@ 2010-01-20 21:47 ` jason at gcc dot gnu dot org
  2010-01-20 22:15 ` jason at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: jason at gcc dot gnu dot org @ 2010-01-20 21:47 UTC (permalink / raw)
  To: gcc-bugs



-- 

jason at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|unassigned at gcc dot gnu   |jason at gcc dot gnu dot org
                   |dot org                     |
             Status|NEW                         |ASSIGNED
           Keywords|                            |ABI
   Last reconfirmed|2009-10-22 09:32:15         |2010-01-20 21:47:01
               date|                            |


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


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

* [Bug c++/41788] -Wpacked option changes the layout of packed non-POD structs
  2009-10-22  0:05 [Bug c++/41788] New: -Wpacked option changes the layout of packed non-POD structs nenad at tensilica dot com
                   ` (2 preceding siblings ...)
  2010-01-20 21:47 ` jason at gcc dot gnu dot org
@ 2010-01-20 22:15 ` jason at gcc dot gnu dot org
  2010-01-20 23:11 ` jason at gcc dot gnu dot org
  2010-04-09 15:19 ` jason at gcc dot gnu dot org
  5 siblings, 0 replies; 7+ messages in thread
From: jason at gcc dot gnu dot org @ 2010-01-20 22:15 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from jason at gcc dot gnu dot org  2010-01-20 22:15 -------
Subject: Bug 41788

Author: jason
Date: Wed Jan 20 22:14:51 2010
New Revision: 156088

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=156088
Log:
        PR c++/41788
        * class.c (layout_class_type): Set packed_maybe_necessary for packed
        non-PODs.

Added:
    trunk/gcc/testsuite/g++.dg/abi/packed1.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/class.c
    trunk/gcc/testsuite/ChangeLog


-- 


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


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

* [Bug c++/41788] -Wpacked option changes the layout of packed non-POD structs
  2009-10-22  0:05 [Bug c++/41788] New: -Wpacked option changes the layout of packed non-POD structs nenad at tensilica dot com
                   ` (3 preceding siblings ...)
  2010-01-20 22:15 ` jason at gcc dot gnu dot org
@ 2010-01-20 23:11 ` jason at gcc dot gnu dot org
  2010-04-09 15:19 ` jason at gcc dot gnu dot org
  5 siblings, 0 replies; 7+ messages in thread
From: jason at gcc dot gnu dot org @ 2010-01-20 23:11 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from jason at gcc dot gnu dot org  2010-01-20 23:11 -------
Fixed for 4.5.


-- 

jason at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |FIXED
   Target Milestone|---                         |4.5.0


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


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

* [Bug c++/41788] -Wpacked option changes the layout of packed non-POD structs
  2009-10-22  0:05 [Bug c++/41788] New: -Wpacked option changes the layout of packed non-POD structs nenad at tensilica dot com
                   ` (4 preceding siblings ...)
  2010-01-20 23:11 ` jason at gcc dot gnu dot org
@ 2010-04-09 15:19 ` jason at gcc dot gnu dot org
  5 siblings, 0 replies; 7+ messages in thread
From: jason at gcc dot gnu dot org @ 2010-04-09 15:19 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from jason at gcc dot gnu dot org  2010-04-09 15:19 -------
Subject: Bug 41788

Author: jason
Date: Fri Apr  9 15:19:17 2010
New Revision: 158166

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=158166
Log:
        PR c++/41788
        * stor-layout.c (finalize_record_size): Don't change TYPE_PACKED
        based on a warning flag.

Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/stor-layout.c


-- 


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


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

end of thread, other threads:[~2010-04-09 15:19 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-10-22  0:05 [Bug c++/41788] New: -Wpacked option changes the layout of packed non-POD structs nenad at tensilica dot com
2009-10-22  9:32 ` [Bug c++/41788] " rguenth at gcc dot gnu dot org
2009-10-22 16:23 ` nenad at tensilica dot com
2010-01-20 21:47 ` jason at gcc dot gnu dot org
2010-01-20 22:15 ` jason at gcc dot gnu dot org
2010-01-20 23:11 ` jason at gcc dot gnu dot org
2010-04-09 15:19 ` 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).