Bug List: (This bug is not in your last search results)   Show last search results      Search page      Enter new bug
Bug#: 36137
Product:  
Component:  
Status: RESOLVED
Resolution: FIXED
Assigned To: Jakub Jelinek <jakub@gcc.gnu.org>
Host:
Reported against  
Priority:  
Severity:  
Target Milestone:  
 
 
Target:
Reporter: Benjamin Otte <otte@gnome.org>
Add CC:
CC:
Remove selected CCs
Build:
Patch URL:
Summary:
Keywords:
Known to work:
Known to fail:

Attachment Description Type Created Size Actions
test.c testcase text/x-csrc 2008-05-05 14:17 181 bytes Edit
Create a New Attachment (proposed patch, testcase, etc.) View All

Bug 36137 depends on: Show dependency tree
Show dependency graph
Bug 36137 blocks:

Additional Comments:






View Bug Activity   |   Format For Printing   |   Clone This Bug


Description:   Last confirmed: 2008-05-06 10:50 Opened: 2008-05-05 14:16
The attached program prints (unsigned) -1 as opposed to 1.
This doesn't happen if intermediate variables are used somewhere in the
process.

I tested gcc 3.4, 4.2.3 (on both x86 and x86-64) with -O0 and -O2, all ended up
with -1.
suncc printed 1.

------- Comment #1 From Benjamin Otte 2008-05-05 14:17 -------
Created an attachment (id=15581) [edit]
testcase

------- Comment #2 From Tom Tromey 2008-05-05 19:10 -------
test.c.t02.original says:

  u = MAX_EXPR <(unsigned int) i, 1>;

... but this is wrong.

------- Comment #3 From Tom Tromey 2008-05-05 22:27 -------
fold_binary sees both MAX_EXPRs and reassociates.
(I think this is why it works with intermediate variables.)

Then associate_trees creates a new MAX_EXPR, converting each
argument to unsigned:

  return fold_build2 (code, type, fold_convert (type, t1),
                      fold_convert (type, t2));

So, this is where the error enters.
I'm not sure where this is best fixed though.

------- Comment #4 From Jakub Jelinek 2008-05-07 07:41 -------
Subject: Bug 36137

Author: jakub
Date: Wed May  7 07:40:01 2008
New Revision: 135028

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=135028
Log:
        PR middle-end/36137
        * fold-const.c (fold_binary): Use STRIP_SIGN_NOPS instead of
        STRIP_NOPS on arguments even for MIN_EXPR and MAX_EXPR.

        * gcc.c-torture/execute/20080506-1.c: New test.

Added:
    trunk/gcc/testsuite/gcc.c-torture/execute/20080506-1.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/fold-const.c
    trunk/gcc/testsuite/ChangeLog

------- Comment #5 From Jakub Jelinek 2008-05-07 07:59 -------
Subject: Bug 36137

Author: jakub
Date: Wed May  7 07:58:33 2008
New Revision: 135031

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=135031
Log:
        PR middle-end/36137
        * fold-const.c (fold_binary): Use STRIP_SIGN_NOPS instead of
        STRIP_NOPS on arguments even for MIN_EXPR and MAX_EXPR.

        * gcc.c-torture/execute/20080506-1.c: New test.

Added:
    branches/gcc-4_3-branch/gcc/testsuite/gcc.c-torture/execute/20080506-1.c
Modified:
    branches/gcc-4_3-branch/gcc/ChangeLog
    branches/gcc-4_3-branch/gcc/fold-const.c
    branches/gcc-4_3-branch/gcc/testsuite/ChangeLog

------- Comment #6 From Jakub Jelinek 2008-05-07 08:06 -------
Fixed in 4.3 and on the trunk.

Bug List: (This bug is not in your last search results)   Show last search results      Search page      Enter new bug