public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/40404]  New: Comparison involving unsigned int:17 bitfield seems wrong
@ 2009-06-10 18:38 foo at mailinator dot com
  2009-06-10 18:41 ` [Bug c/40404] " pinskia at gcc dot gnu dot org
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: foo at mailinator dot com @ 2009-06-10 18:38 UTC (permalink / raw)
  To: gcc-bugs

#include <stdio.h>
struct S {
    unsigned int ui17 : 17;
} s;
int main()
{
    s.ui17 = 0x1ffff;
    printf("%x\n", (unsigned int)s.ui17);
    if (s.ui17 >= 0xfffffffeu)
        puts("FAIL");
    return 0;
}

Maybe I don't understand GCC's rules for the promotion of bitfields, but it
seems to me that s.ui17 should evaluate to ((unsigned int)0x1ffff), which is
less than 0xfffffffeu, so "FAIL" should not be printed. But "FAIL" is printed.
I can't explain why; it's almost as if GCC is truncating the rhs to 0x1fffe
before doing the comparison!

Changing s.ui17 from 17 bits to 15 bits makes the test pass (i.e., not print
"FAIL"). I believe in that case GCC promotes s.ui17 to "unsigned short"... but
that should undergo usual arithmetic conversion to "unsigned int" at which
point we ought to see the same FAIL behavior happening.

Reproduced with GCC 4.2.4 and 4.3.3.


-- 
           Summary: Comparison involving unsigned int:17 bitfield seems
                    wrong
           Product: gcc
           Version: 4.3.3
            Status: UNCONFIRMED
          Severity: minor
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: foo at mailinator dot com


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


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

* [Bug c/40404] Comparison involving unsigned int:17 bitfield seems wrong
  2009-06-10 18:38 [Bug c/40404] New: Comparison involving unsigned int:17 bitfield seems wrong foo at mailinator dot com
@ 2009-06-10 18:41 ` pinskia at gcc dot gnu dot org
  2009-06-10 20:15 ` rguenth at gcc dot gnu dot org
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2009-06-10 18:41 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from pinskia at gcc dot gnu dot org  2009-06-10 18:41 -------
unsigned int:17  gets promoted to int IIRC.


-- 


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


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

* [Bug c/40404] Comparison involving unsigned int:17 bitfield seems wrong
  2009-06-10 18:38 [Bug c/40404] New: Comparison involving unsigned int:17 bitfield seems wrong foo at mailinator dot com
  2009-06-10 18:41 ` [Bug c/40404] " pinskia at gcc dot gnu dot org
@ 2009-06-10 20:15 ` rguenth at gcc dot gnu dot org
  2009-06-10 20:26 ` rguenth at gcc dot gnu dot org
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2009-06-10 20:15 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from rguenth at gcc dot gnu dot org  2009-06-10 20:15 -------
This has been fixed in GCC 4.4, likely by removing some shorten-compare stuff
in the frontend.


-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |rguenth at gcc dot gnu dot
                   |                            |org
      Known to fail|                            |4.3.3
      Known to work|                            |4.4.0


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


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

* [Bug c/40404] Comparison involving unsigned int:17 bitfield seems wrong
  2009-06-10 18:38 [Bug c/40404] New: Comparison involving unsigned int:17 bitfield seems wrong foo at mailinator dot com
  2009-06-10 18:41 ` [Bug c/40404] " pinskia at gcc dot gnu dot org
  2009-06-10 20:15 ` rguenth at gcc dot gnu dot org
@ 2009-06-10 20:26 ` rguenth at gcc dot gnu dot org
  2009-06-12 20:41 ` mikpe at it dot uu dot se
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2009-06-10 20:26 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from rguenth at gcc dot gnu dot org  2009-06-10 20:25 -------
Can someone identify the patch that fixed that on the trunk?


-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |wrong-code


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


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

* [Bug c/40404] Comparison involving unsigned int:17 bitfield seems wrong
  2009-06-10 18:38 [Bug c/40404] New: Comparison involving unsigned int:17 bitfield seems wrong foo at mailinator dot com
                   ` (2 preceding siblings ...)
  2009-06-10 20:26 ` rguenth at gcc dot gnu dot org
@ 2009-06-12 20:41 ` mikpe at it dot uu dot se
  2009-06-13 13:56 ` rguenth at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: mikpe at it dot uu dot se @ 2009-06-12 20:41 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from mikpe at it dot uu dot se  2009-06-12 20:41 -------
(In reply to comment #3)
> Can someone identify the patch that fixed that on the trunk?

I've identified r139702, the fix for PR37005, as the revision which fixed this
test case on gcc-4.4. That change applies easily to current gcc-4.3, so I tried
it and it did fix this test case also for gcc-4.3.


-- 


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


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

* [Bug c/40404] Comparison involving unsigned int:17 bitfield seems wrong
  2009-06-10 18:38 [Bug c/40404] New: Comparison involving unsigned int:17 bitfield seems wrong foo at mailinator dot com
                   ` (3 preceding siblings ...)
  2009-06-12 20:41 ` mikpe at it dot uu dot se
@ 2009-06-13 13:56 ` rguenth at gcc dot gnu dot org
  2009-06-17 12:29 ` [Bug middle-end/40404] " rguenth at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2009-06-13 13:56 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from rguenth at gcc dot gnu dot org  2009-06-13 13:56 -------
Thanks.  I'll have a look.


-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|unassigned at gcc dot gnu   |rguenth at gcc dot gnu dot
                   |dot org                     |org
             Status|UNCONFIRMED                 |ASSIGNED
     Ever Confirmed|0                           |1
   Last reconfirmed|0000-00-00 00:00:00         |2009-06-13 13:56:16
               date|                            |


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


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

* [Bug middle-end/40404] Comparison involving unsigned int:17 bitfield seems wrong
  2009-06-10 18:38 [Bug c/40404] New: Comparison involving unsigned int:17 bitfield seems wrong foo at mailinator dot com
                   ` (4 preceding siblings ...)
  2009-06-13 13:56 ` rguenth at gcc dot gnu dot org
@ 2009-06-17 12:29 ` rguenth at gcc dot gnu dot org
  2009-06-17 12:31 ` rguenth at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2009-06-17 12:29 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from rguenth at gcc dot gnu dot org  2009-06-17 12:28 -------
Subject: Bug 40404

Author: rguenth
Date: Wed Jun 17 12:28:43 2009
New Revision: 148605

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=148605
Log:
2009-06-17  Richard Guenther  <rguenther@suse.de>

        PR middle-end/40404
        * gcc.c-torture/execute/pr40404.c: New testcase.

Added:
    branches/gcc-4_4-branch/gcc/testsuite/gcc.c-torture/execute/pr40404.c
Modified:
    branches/gcc-4_4-branch/gcc/testsuite/ChangeLog


-- 


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


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

* [Bug middle-end/40404] Comparison involving unsigned int:17 bitfield seems wrong
  2009-06-10 18:38 [Bug c/40404] New: Comparison involving unsigned int:17 bitfield seems wrong foo at mailinator dot com
                   ` (5 preceding siblings ...)
  2009-06-17 12:29 ` [Bug middle-end/40404] " rguenth at gcc dot gnu dot org
@ 2009-06-17 12:31 ` rguenth at gcc dot gnu dot org
  2009-06-17 13:06 ` rguenth at gcc dot gnu dot org
  2009-06-17 13:07 ` 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-17 12:31 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #7 from rguenth at gcc dot gnu dot org  2009-06-17 12:31 -------
Subject: Bug 40404

Author: rguenth
Date: Wed Jun 17 12:30:54 2009
New Revision: 148606

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=148606
Log:
2009-06-17  Richard Guenther  <rguenther@suse.de>

        PR middle-end/40404
        * gcc.c-torture/execute/pr40404.c: New testcase.

Added:
    trunk/gcc/testsuite/gcc.c-torture/execute/pr40404.c
Modified:
    trunk/gcc/testsuite/ChangeLog


-- 


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


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

* [Bug middle-end/40404] Comparison involving unsigned int:17 bitfield seems wrong
  2009-06-10 18:38 [Bug c/40404] New: Comparison involving unsigned int:17 bitfield seems wrong foo at mailinator dot com
                   ` (6 preceding siblings ...)
  2009-06-17 12:31 ` rguenth at gcc dot gnu dot org
@ 2009-06-17 13:06 ` rguenth at gcc dot gnu dot org
  2009-06-17 13:07 ` 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-17 13:06 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #8 from rguenth at gcc dot gnu dot org  2009-06-17 13:06 -------
Subject: Bug 40404

Author: rguenth
Date: Wed Jun 17 13:06:21 2009
New Revision: 148610

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=148610
Log:
2009-06-17  Richard Guenther  <rguenther@suse.de>

        PR middle-end/40404
        * fold-const.c (fold_binary): Verify the type precision of the
        stripped arguments of the comparison are the same before
        folding the comparison.

        * gcc.c-torture/execute/pr40404.c: New testcase.

Added:
    branches/gcc-4_3-branch/gcc/testsuite/gcc.c-torture/execute/pr40404.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


-- 


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


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

* [Bug middle-end/40404] Comparison involving unsigned int:17 bitfield seems wrong
  2009-06-10 18:38 [Bug c/40404] New: Comparison involving unsigned int:17 bitfield seems wrong foo at mailinator dot com
                   ` (7 preceding siblings ...)
  2009-06-17 13:06 ` rguenth at gcc dot gnu dot org
@ 2009-06-17 13:07 ` 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-17 13:07 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #9 from rguenth at gcc dot gnu dot org  2009-06-17 13:07 -------
Fixed.


-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
      Known to work|4.4.0                       |4.3.4 4.4.0
         Resolution|                            |FIXED
   Target Milestone|---                         |4.3.4


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


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

end of thread, other threads:[~2009-06-17 13:07 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-06-10 18:38 [Bug c/40404] New: Comparison involving unsigned int:17 bitfield seems wrong foo at mailinator dot com
2009-06-10 18:41 ` [Bug c/40404] " pinskia at gcc dot gnu dot org
2009-06-10 20:15 ` rguenth at gcc dot gnu dot org
2009-06-10 20:26 ` rguenth at gcc dot gnu dot org
2009-06-12 20:41 ` mikpe at it dot uu dot se
2009-06-13 13:56 ` rguenth at gcc dot gnu dot org
2009-06-17 12:29 ` [Bug middle-end/40404] " rguenth at gcc dot gnu dot org
2009-06-17 12:31 ` rguenth at gcc dot gnu dot org
2009-06-17 13:06 ` rguenth at gcc dot gnu dot org
2009-06-17 13:07 ` 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).