public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/60229] New: wrong code at -O2 and -O3 on x86_64-linux-gnu
@ 2014-02-16 20:28 su at cs dot ucdavis.edu
  2014-02-16 23:09 ` [Bug tree-optimization/60229] " pinskia at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: su at cs dot ucdavis.edu @ 2014-02-16 20:28 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 60229
           Summary: wrong code at -O2 and -O3 on x86_64-linux-gnu
           Product: gcc
           Version: 4.7.4
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: su at cs dot ucdavis.edu

The latest gcc 4.7 branch miscompiles the following code on x86_64-linux at -O2
and -O3 in both 32-bit and 64-bit modes.

It also affects 4.6.x, but not 4.8.x and the current gcc trunk. 

The issue seems to be considering signed short and signed char for overflows,
but neither overflows. 

$ gcc-trunk -O2 small.c    
$ a.out
$ gcc-4.8.2 -O2 small.c
$ a.out
$ gcc-4.7.3 -O2 small.c
$ a.out
^C
$ gcc-4.7-branch -O2 small.c
$ a.out
^C
$ gcc-4.7-branch -v
Using built-in specs.
COLLECT_GCC=gcc-4.7-branch
COLLECT_LTO_WRAPPER=/usr/local/gcc47-branch/bin/../libexec/gcc/x86_64-unknown-linux-gnu/4.7.4/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: ../gcc-4.7/configure --enable-languages=c,c++
Thread model: posix
gcc version 4.7.4 20140209 (prerelease) [gcc-4_7-branch revision 207641] (GCC) 
$ 


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


short a;

int 
main() 
{
  for (; a >= 0; a++)
    ;

  return 0;
}


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

* [Bug tree-optimization/60229] wrong code at -O2 and -O3 on x86_64-linux-gnu
  2014-02-16 20:28 [Bug tree-optimization/60229] New: wrong code at -O2 and -O3 on x86_64-linux-gnu su at cs dot ucdavis.edu
@ 2014-02-16 23:09 ` pinskia at gcc dot gnu.org
  2014-02-16 23:10 ` pinskia at gcc dot gnu.org
  2014-02-17  9:54 ` jakub at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2014-02-16 23:09 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

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

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Dup of bug 35634.

*** This bug has been marked as a duplicate of bug 35634 ***


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

* [Bug tree-optimization/60229] wrong code at -O2 and -O3 on x86_64-linux-gnu
  2014-02-16 20:28 [Bug tree-optimization/60229] New: wrong code at -O2 and -O3 on x86_64-linux-gnu su at cs dot ucdavis.edu
  2014-02-16 23:09 ` [Bug tree-optimization/60229] " pinskia at gcc dot gnu.org
@ 2014-02-16 23:10 ` pinskia at gcc dot gnu.org
  2014-02-17  9:54 ` jakub at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2014-02-16 23:10 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Note there is no overflow happening here at all.  In that a++ is the same as a
= a + 1 which is the same as a = (short)(((int)a) + 1) due to promotion rules
in C.


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

* [Bug tree-optimization/60229] wrong code at -O2 and -O3 on x86_64-linux-gnu
  2014-02-16 20:28 [Bug tree-optimization/60229] New: wrong code at -O2 and -O3 on x86_64-linux-gnu su at cs dot ucdavis.edu
  2014-02-16 23:09 ` [Bug tree-optimization/60229] " pinskia at gcc dot gnu.org
  2014-02-16 23:10 ` pinskia at gcc dot gnu.org
@ 2014-02-17  9:54 ` jakub at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: jakub at gcc dot gnu.org @ 2014-02-17  9:54 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jakub at gcc dot gnu.org

--- Comment #4 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Well, the conversion is implementation-defined behavior, and GCC documents what
it does in that case (does it?) and thus you can rely on it, and given that
other compilers also have simimilar implementation-defined behavior choice for
that case, you can portably assume it unless you are targetting extinct
architectures.


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

end of thread, other threads:[~2014-02-17  9:54 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-02-16 20:28 [Bug tree-optimization/60229] New: wrong code at -O2 and -O3 on x86_64-linux-gnu su at cs dot ucdavis.edu
2014-02-16 23:09 ` [Bug tree-optimization/60229] " pinskia at gcc dot gnu.org
2014-02-16 23:10 ` pinskia at gcc dot gnu.org
2014-02-17  9:54 ` jakub at gcc dot gnu.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).