public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/29913]  New: argument width changes from inlined method definition with -O2
@ 2006-11-20 13:02 timj at gtk dot org
  2006-11-20 13:08 ` [Bug c++/29913] " timj at gtk dot org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: timj at gtk dot org @ 2006-11-20 13:02 UTC (permalink / raw)
  To: gcc-bugs

using g++ (GCC) 4.2.0 20060530 (experimental) on linux i386, a code snippet
could be found, for which the width of the first enum argument of a class
method changes, depending on whether the method is defined inside or outside
the class definition. example code follows, optimization -O2 is required to
trigger the bug.


-- 
           Summary: argument width changes from inlined method definition
                    with -O2
           Product: gcc
           Version: 4.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: timj at gtk dot org


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


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

* [Bug c++/29913] argument width changes from inlined method definition with -O2
  2006-11-20 13:02 [Bug c++/29913] New: argument width changes from inlined method definition with -O2 timj at gtk dot org
@ 2006-11-20 13:08 ` timj at gtk dot org
  2006-11-20 13:45 ` rguenth at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: timj at gtk dot org @ 2006-11-20 13:08 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from timj at gtk dot org  2006-11-20 13:07 -------
Created an attachment (id=12652)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=12652&action=view)
testcase, demonstrating argument width changes

compiling and executing the attached testcase with -Wall -O2 produces:
i++ = 7
i++ = 7
i++ = 7
i++ = 7
i++ = 7

changing optimization to -O1 or defining INLINED_METHOD to 1 produces the
expected:
i++ = 7
i++ = 8
i++ = 9
i++ = 10
i++ = 11


-- 


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


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

* [Bug c++/29913] argument width changes from inlined method definition with -O2
  2006-11-20 13:02 [Bug c++/29913] New: argument width changes from inlined method definition with -O2 timj at gtk dot org
  2006-11-20 13:08 ` [Bug c++/29913] " timj at gtk dot org
@ 2006-11-20 13:45 ` rguenth at gcc dot gnu dot org
  2006-11-20 13:55 ` timj at gtk dot org
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2006-11-20 13:45 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from rguenth at gcc dot gnu dot org  2006-11-20 13:44 -------
This is invalid.  In C++ the precision of enums is the least number of bits
required to represent all values.  In this case, 3.


-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


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


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

* [Bug c++/29913] argument width changes from inlined method definition with -O2
  2006-11-20 13:02 [Bug c++/29913] New: argument width changes from inlined method definition with -O2 timj at gtk dot org
  2006-11-20 13:08 ` [Bug c++/29913] " timj at gtk dot org
  2006-11-20 13:45 ` rguenth at gcc dot gnu dot org
@ 2006-11-20 13:55 ` timj at gtk dot org
  2006-11-20 14:53 ` pinskia at gcc dot gnu dot org
  2006-11-20 17:13 ` rguenth at gcc dot gnu dot org
  4 siblings, 0 replies; 6+ messages in thread
From: timj at gtk dot org @ 2006-11-20 13:55 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from timj at gtk dot org  2006-11-20 13:55 -------
Richard, please take another look at the bug report.

note that the printed number change values depending on wether a class method
is inlined and compiled with -O2, or whether those 2 conditions are not met.
i think that, regardless of how g++ chooses to implement the C++ standard, the
calculated values shouldn't depend on -O1 vs. -O2 or on whether a class methopd
is inlined or not.

please also note that g++-3.4 and g++-3.3 both do not exhibit this behaviour,
so if you still want to close this bug report as invalid, please give a short
explanaition on why programs wich depend on the i++ result to increment, should
fail with gcc-4.2 when they worked perfectly fine with 3.3 and 3.4.


-- 

timj at gtk dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |UNCONFIRMED
         Resolution|INVALID                     |


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


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

* [Bug c++/29913] argument width changes from inlined method definition with -O2
  2006-11-20 13:02 [Bug c++/29913] New: argument width changes from inlined method definition with -O2 timj at gtk dot org
                   ` (2 preceding siblings ...)
  2006-11-20 13:55 ` timj at gtk dot org
@ 2006-11-20 14:53 ` pinskia at gcc dot gnu dot org
  2006-11-20 17:13 ` rguenth at gcc dot gnu dot org
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2006-11-20 14:53 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from pinskia at gcc dot gnu dot org  2006-11-20 14:52 -------
(In reply to comment #3)
> Richard, please take another look at the bug report.

I just did.  The behavior is undefined as the enum's size is not enough to fit
12.

> 
> note that the printed number change values depending on wether a class method
> is inlined and compiled with -O2, or whether those 2 conditions are not met.
> i think that, regardless of how g++ chooses to implement the C++ standard, the
> calculated values shouldn't depend on -O1 vs. -O2 or on whether a class methopd
> is inlined or not.
Yes and the C++ standard says this is undefined behavior which means the output
can be different between runs (in this case it is different between
optimization levels and inlining).

> 
> please also note that g++-3.4 and g++-3.3 both do not exhibit this behaviour,
> so if you still want to close this bug report as invalid, please give a short
> explanaition on why programs wich depend on the i++ result to increment, should
> fail with gcc-4.2 when they worked perfectly fine with 3.3 and 3.4.

3.4 (and before) did not implement this part of the C++ standard and got some
enum values incorrect.


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


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


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

* [Bug c++/29913] argument width changes from inlined method definition with -O2
  2006-11-20 13:02 [Bug c++/29913] New: argument width changes from inlined method definition with -O2 timj at gtk dot org
                   ` (3 preceding siblings ...)
  2006-11-20 14:53 ` pinskia at gcc dot gnu dot org
@ 2006-11-20 17:13 ` rguenth at gcc dot gnu dot org
  4 siblings, 0 replies; 6+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2006-11-20 17:13 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from rguenth at gcc dot gnu dot org  2006-11-20 17:13 -------
btw. you can easily work around by appending a dummy value to the enum of value
INT_MAX.


-- 


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


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

end of thread, other threads:[~2006-11-20 17:13 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-11-20 13:02 [Bug c++/29913] New: argument width changes from inlined method definition with -O2 timj at gtk dot org
2006-11-20 13:08 ` [Bug c++/29913] " timj at gtk dot org
2006-11-20 13:45 ` rguenth at gcc dot gnu dot org
2006-11-20 13:55 ` timj at gtk dot org
2006-11-20 14:53 ` pinskia at gcc dot gnu dot org
2006-11-20 17:13 ` rguenth 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).