public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/39231]  New: Optimized code gives wrong result
@ 2009-02-18 14:33 gabriel dot campana at free dot fr
  2009-02-18 14:37 ` [Bug c/39231] " rguenth at gcc dot gnu dot org
  0 siblings, 1 reply; 2+ messages in thread
From: gabriel dot campana at free dot fr @ 2009-02-18 14:33 UTC (permalink / raw)
  To: gcc-bugs

The following code gives wrong result with -O2 and above :
% gcc -O0 -o example example.c && ./example
1
% gcc -O2 -o example example.c && ./example
0

The bug is triggered on i486 platform, with gcc 4.3.2 but not with gcc 4.1.2.


#include <stdio.h>

int main(void) {
    volatile int y;
    int x;

    y = 0x80000000;
    x = y;

    if (x < 0)
        x = -x;

    printf("%d\n", x == 0x80000000);

    return 0;
}


-- 
           Summary: Optimized code gives wrong result
           Product: gcc
           Version: 4.3.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: gabriel dot campana at free dot fr
 GCC build triplet: i486-linux-gnu
  GCC host triplet: i486-linux-gnu
GCC target triplet: i486-linux-gnu


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


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

* [Bug c/39231] Optimized code gives wrong result
  2009-02-18 14:33 [Bug c/39231] New: Optimized code gives wrong result gabriel dot campana at free dot fr
@ 2009-02-18 14:37 ` rguenth at gcc dot gnu dot org
  0 siblings, 0 replies; 2+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2009-02-18 14:37 UTC (permalink / raw)
  To: gcc-bugs

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 647 bytes --]



------- Comment #1 from rguenth at gcc dot gnu dot org  2009-02-18 14:37 -------
gcc -o t t.c -O2 -Wstrict-overflow
t.c: In function ‘main’:
t.c:13: warning: assuming signed overflow does not occur when simplifying
conditional to constant

negating signed 0x80000000 invokes undefined behavior.


-- 

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=39231


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

end of thread, other threads:[~2009-02-18 14:37 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-02-18 14:33 [Bug c/39231] New: Optimized code gives wrong result gabriel dot campana at free dot fr
2009-02-18 14:37 ` [Bug c/39231] " 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).