public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/39867]  New: [4.4 Regression] Wrong result of conditional operator exp < 2 ? 2U : (unsigned int) exp
@ 2009-04-23 13:34 vincent at vinc17 dot org
  2009-04-23 13:45 ` [Bug c/39867] " vincent at vinc17 dot org
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: vincent at vinc17 dot org @ 2009-04-23 13:34 UTC (permalink / raw)
  To: gcc-bugs

With GCC 4.4.0, the following program outputs 4294967295 instead of 2:

#include <stdio.h>

int main (void)
{
  int exp = -1;
  printf ("%u\n", exp < 2 ? 2U : (unsigned int) exp);
  return 0;
}

Note: I've tried with gcc-snapshot under a Debian/unstable x86_64 Linux
machine, but the same bug was reported to me, with gcc-4.4.0 (it was found by
Philippe Theveny, who works on MPFR, and the MPFR tests fail because of that).

GCC 4.3.3 does not have this problem.


-- 
           Summary: [4.4 Regression] Wrong result of conditional operator
                    exp < 2 ? 2U : (unsigned int) exp
           Product: gcc
           Version: 4.4.0
            Status: UNCONFIRMED
          Severity: major
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: vincent at vinc17 dot org


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


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

* [Bug c/39867] [4.4 Regression] Wrong result of conditional operator exp < 2 ? 2U : (unsigned int) exp
  2009-04-23 13:34 [Bug c/39867] New: [4.4 Regression] Wrong result of conditional operator exp < 2 ? 2U : (unsigned int) exp vincent at vinc17 dot org
@ 2009-04-23 13:45 ` vincent at vinc17 dot org
  2009-04-23 13:46 ` [Bug middle-end/39867] " rguenth at gcc dot gnu dot org
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: vincent at vinc17 dot org @ 2009-04-23 13:45 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from vincent at vinc17 dot org  2009-04-23 13:44 -------
I forgot to say: the bug occurs whether one compiles with optimizations or not.


-- 


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


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

* [Bug middle-end/39867] [4.4 Regression] Wrong result of conditional operator exp < 2 ? 2U : (unsigned int) exp
  2009-04-23 13:34 [Bug c/39867] New: [4.4 Regression] Wrong result of conditional operator exp < 2 ? 2U : (unsigned int) exp vincent at vinc17 dot org
  2009-04-23 13:45 ` [Bug c/39867] " vincent at vinc17 dot org
@ 2009-04-23 13:46 ` rguenth at gcc dot gnu dot org
  2009-04-23 15:16 ` [Bug middle-end/39867] [4.4/4.5 " bonzini at gnu dot org
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2009-04-23 13:46 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from rguenth at gcc dot gnu dot org  2009-04-23 13:46 -------
We fold it to

  return (int) MAX_EXPR <(unsigned int) exp, 2>;

which is obviously bogus.  4.3 produced

  return NON_LVALUE_EXPR <MAX_EXPR <exp, 2>>;

which is correct (well, but has likely mismatched types if the 2 is still
unsigned).

Confirmed.


-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |rguenth at gcc dot gnu dot
                   |                            |org
             Status|UNCONFIRMED                 |NEW
          Component|c                           |middle-end
     Ever Confirmed|0                           |1
           Keywords|                            |wrong-code
   Last reconfirmed|0000-00-00 00:00:00         |2009-04-23 13:46:39
               date|                            |
   Target Milestone|---                         |4.4.0


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


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

* [Bug middle-end/39867] [4.4/4.5 Regression] Wrong result of conditional operator exp < 2 ? 2U : (unsigned int) exp
  2009-04-23 13:34 [Bug c/39867] New: [4.4 Regression] Wrong result of conditional operator exp < 2 ? 2U : (unsigned int) exp vincent at vinc17 dot org
  2009-04-23 13:45 ` [Bug c/39867] " vincent at vinc17 dot org
  2009-04-23 13:46 ` [Bug middle-end/39867] " rguenth at gcc dot gnu dot org
@ 2009-04-23 15:16 ` bonzini at gnu dot org
  2009-04-23 15:23 ` bonzini at gnu dot org
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: bonzini at gnu dot org @ 2009-04-23 15:16 UTC (permalink / raw)
  To: gcc-bugs



-- 

bonzini at gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|[4.4 Regression] Wrong      |[4.4/4.5 Regression] Wrong
                   |result of conditional       |result of conditional
                   |operator exp < 2 ? 2U :     |operator exp < 2 ? 2U :
                   |(unsigned int) exp          |(unsigned int) exp
   Target Milestone|4.4.0                       |4.4.1


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


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

* [Bug middle-end/39867] [4.4/4.5 Regression] Wrong result of conditional operator exp < 2 ? 2U : (unsigned int) exp
  2009-04-23 13:34 [Bug c/39867] New: [4.4 Regression] Wrong result of conditional operator exp < 2 ? 2U : (unsigned int) exp vincent at vinc17 dot org
                   ` (2 preceding siblings ...)
  2009-04-23 15:16 ` [Bug middle-end/39867] [4.4/4.5 " bonzini at gnu dot org
@ 2009-04-23 15:23 ` bonzini at gnu dot org
  2009-04-23 15:52 ` bonzini at gnu dot org
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: bonzini at gnu dot org @ 2009-04-23 15:23 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from bonzini at gnu dot org  2009-04-23 15:22 -------
Created an attachment (id=17684)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=17684&action=view)
patch

Bootstrapped but not yet regtested.  Testcase:

/* { dg-do link } */
/* { dg-options "-O2" } */

int main (void)
{
  int exp = -1;
  /* Wrong folding of the LHS to an unsigned MAX leads to 4294967295 > 2.  */
  if (("%u\n", exp < 2 ? 2U : (unsigned int) exp) > 2)
    link_error ();
  return 0;
}


-- 


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


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

* [Bug middle-end/39867] [4.4/4.5 Regression] Wrong result of conditional operator exp < 2 ? 2U : (unsigned int) exp
  2009-04-23 13:34 [Bug c/39867] New: [4.4 Regression] Wrong result of conditional operator exp < 2 ? 2U : (unsigned int) exp vincent at vinc17 dot org
                   ` (3 preceding siblings ...)
  2009-04-23 15:23 ` bonzini at gnu dot org
@ 2009-04-23 15:52 ` bonzini at gnu dot org
  2009-04-24 10:29 ` bonzini at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: bonzini at gnu dot org @ 2009-04-23 15:52 UTC (permalink / raw)
  To: gcc-bugs



-- 

bonzini at gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|unassigned at gcc dot gnu   |bonzini at gnu dot org
                   |dot org                     |
             Status|NEW                         |ASSIGNED
   Last reconfirmed|2009-04-23 13:46:39         |2009-04-23 15:52:19
               date|                            |


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


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

* [Bug middle-end/39867] [4.4/4.5 Regression] Wrong result of conditional operator exp < 2 ? 2U : (unsigned int) exp
  2009-04-23 13:34 [Bug c/39867] New: [4.4 Regression] Wrong result of conditional operator exp < 2 ? 2U : (unsigned int) exp vincent at vinc17 dot org
                   ` (4 preceding siblings ...)
  2009-04-23 15:52 ` bonzini at gnu dot org
@ 2009-04-24 10:29 ` bonzini at gcc dot gnu dot org
  2009-04-24 11:35 ` bonzini at gnu dot org
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: bonzini at gcc dot gnu dot org @ 2009-04-24 10:29 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from bonzini at gnu dot org  2009-04-24 10:29 -------
Subject: Bug 39867

Author: bonzini
Date: Fri Apr 24 10:29:18 2009
New Revision: 146695

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=146695
Log:
2009-04-24  Paolo Bonzini  <bonzini@gnu.org>

        PR middle-end/39867
        * fold-const.c (fold_cond_expr_with_comparison): When folding
        > and >= to MAX, make sure the MAX uses the same type as the
        comparison operands.

testsuite:
2009-04-24  Paolo Bonzini  <bonzini@gnu.org>

        PR middle-end/39867
        * gcc.dg/pr39867.c: New.


Added:
    trunk/gcc/testsuite/gcc.dg/pr39867.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/fold-const.c
    trunk/gcc/testsuite/ChangeLog


-- 


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


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

* [Bug middle-end/39867] [4.4/4.5 Regression] Wrong result of conditional operator exp < 2 ? 2U : (unsigned int) exp
  2009-04-23 13:34 [Bug c/39867] New: [4.4 Regression] Wrong result of conditional operator exp < 2 ? 2U : (unsigned int) exp vincent at vinc17 dot org
                   ` (5 preceding siblings ...)
  2009-04-24 10:29 ` bonzini at gcc dot gnu dot org
@ 2009-04-24 11:35 ` bonzini at gnu dot org
  2009-04-24 11:35 ` bonzini at gcc dot gnu dot org
  2009-06-23  9:44 ` rguenth at gcc dot gnu dot org
  8 siblings, 0 replies; 10+ messages in thread
From: bonzini at gnu dot org @ 2009-04-24 11:35 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from bonzini at gnu dot org  2009-04-24 11:35 -------
Subject: Bug 39867

Author: bonzini
Date: Fri Apr 24 11:34:59 2009
New Revision: 146702

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=146702
Log:
2009-04-24  Paolo Bonzini  <bonzini@gnu.org>

        PR middle-end/39867
        * fold-const.c (fold_cond_expr_with_comparison): When folding
        > and >= to MAX, make sure the MAX uses the same type as the
        comparison's operands.

testsuite:
2009-04-24  Paolo Bonzini  <bonzini@gnu.org>

        PR middle-end/39867
        * gcc.dg/pr39867.c: New.


Added:
    branches/gcc-4_4-branch/gcc/testsuite/gcc.dg/pr39867.c
      - copied unchanged from r146695, trunk/gcc/testsuite/gcc.dg/pr39867.c
Modified:
    branches/gcc-4_4-branch/gcc/ChangeLog
    branches/gcc-4_4-branch/gcc/fold-const.c
    branches/gcc-4_4-branch/gcc/testsuite/ChangeLog


------- Comment #6 from bonzini at gnu dot org  2009-04-24 11:35 -------
committed to both branches.


-- 

bonzini at gnu dot org changed:

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


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


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

* [Bug middle-end/39867] [4.4/4.5 Regression] Wrong result of conditional operator exp < 2 ? 2U : (unsigned int) exp
  2009-04-23 13:34 [Bug c/39867] New: [4.4 Regression] Wrong result of conditional operator exp < 2 ? 2U : (unsigned int) exp vincent at vinc17 dot org
                   ` (6 preceding siblings ...)
  2009-04-24 11:35 ` bonzini at gnu dot org
@ 2009-04-24 11:35 ` bonzini at gcc dot gnu dot org
  2009-06-23  9:44 ` rguenth at gcc dot gnu dot org
  8 siblings, 0 replies; 10+ messages in thread
From: bonzini at gcc dot gnu dot org @ 2009-04-24 11:35 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from bonzini at gnu dot org  2009-04-24 11:35 -------
Subject: Bug 39867

Author: bonzini
Date: Fri Apr 24 11:34:59 2009
New Revision: 146702

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=146702
Log:
2009-04-24  Paolo Bonzini  <bonzini@gnu.org>

        PR middle-end/39867
        * fold-const.c (fold_cond_expr_with_comparison): When folding
        > and >= to MAX, make sure the MAX uses the same type as the
        comparison's operands.

testsuite:
2009-04-24  Paolo Bonzini  <bonzini@gnu.org>

        PR middle-end/39867
        * gcc.dg/pr39867.c: New.


Added:
    branches/gcc-4_4-branch/gcc/testsuite/gcc.dg/pr39867.c
      - copied unchanged from r146695, trunk/gcc/testsuite/gcc.dg/pr39867.c
Modified:
    branches/gcc-4_4-branch/gcc/ChangeLog
    branches/gcc-4_4-branch/gcc/fold-const.c
    branches/gcc-4_4-branch/gcc/testsuite/ChangeLog


-- 


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


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

* [Bug middle-end/39867] [4.4/4.5 Regression] Wrong result of conditional operator exp < 2 ? 2U : (unsigned int) exp
  2009-04-23 13:34 [Bug c/39867] New: [4.4 Regression] Wrong result of conditional operator exp < 2 ? 2U : (unsigned int) exp vincent at vinc17 dot org
                   ` (7 preceding siblings ...)
  2009-04-24 11:35 ` bonzini at gcc dot gnu dot org
@ 2009-06-23  9:44 ` rguenth at gcc dot gnu dot org
  8 siblings, 0 replies; 10+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2009-06-23  9:44 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #7 from rguenth at gcc dot gnu dot org  2009-06-23 09:43 -------
*** Bug 40524 has been marked as a duplicate of this bug. ***


-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |david dot kirkby at onetel
                   |                            |dot net


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


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

end of thread, other threads:[~2009-06-23  9:44 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-04-23 13:34 [Bug c/39867] New: [4.4 Regression] Wrong result of conditional operator exp < 2 ? 2U : (unsigned int) exp vincent at vinc17 dot org
2009-04-23 13:45 ` [Bug c/39867] " vincent at vinc17 dot org
2009-04-23 13:46 ` [Bug middle-end/39867] " rguenth at gcc dot gnu dot org
2009-04-23 15:16 ` [Bug middle-end/39867] [4.4/4.5 " bonzini at gnu dot org
2009-04-23 15:23 ` bonzini at gnu dot org
2009-04-23 15:52 ` bonzini at gnu dot org
2009-04-24 10:29 ` bonzini at gcc dot gnu dot org
2009-04-24 11:35 ` bonzini at gnu dot org
2009-04-24 11:35 ` bonzini at gcc dot gnu dot org
2009-06-23  9:44 ` 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).