public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* c/6170: Unsigned division bug in gcc 3.x
@ 2002-04-04  2:06 jeroenk
  0 siblings, 0 replies; 2+ messages in thread
From: jeroenk @ 2002-04-04  2:06 UTC (permalink / raw)
  To: gcc-gnats


>Number:         6170
>Category:       c
>Synopsis:       Unsigned division bug in gcc 3.x
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Apr 04 02:06:01 PST 2002
>Closed-Date:
>Last-Modified:
>Originator:     Jeroen Kappert
>Release:        gcc version 3.1 20020130 (Red Hat Linux Rawhide 3.1-0.19)
>Organization:
>Environment:
Red Hat Linux 7.2
>Description:
Unsigned division results into incorrect output.

See the following code:

---
#include <stdio.h>

int main(void) {
      signed short int sT = 3;
    unsigned short int uT = 3;
      signed       int sV = sT / 10;
    unsigned       int uV = uT / 10;;

    printf("Signed   division : Value = %d (0x%04X) / 10 = %5d (0x%08X)\n", sT, sT, sV, sV);
    printf("Unsigned division : Value = %u (0x%04X) / 10 = %5u (0x%08X)\n", uT, uT, uV, uV);
    return 0;
}
---

Which results in the following output:
###
Signed   division : Value = 3 (0x0003) / 10 =     0 (0x00000000)
Unsigned division : Value = 3 (0x0003) / 10 =  8191 (0x00001FFF)
###
Note that the signed and unsigned devision differs!

Now I compiled the same code (on another pc) with gcc version: gcc version 2.95.3 20010315 (SuSE)
which gives the following output:
###
Signed   division : Value = 3 (0x0003) / 10 =     0 (0x00000000)
Unsigned division : Value = 3 (0x0003) / 10 =     0 (0x00000000)
###
Note that this is what i expected!

It seems to me that there is a bug in gcc 3.x
>How-To-Repeat:
see description, to repeat the problem.
>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:


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

* Re: c/6170: Unsigned division bug in gcc 3.x
@ 2002-04-04  2:35 rth
  0 siblings, 0 replies; 2+ messages in thread
From: rth @ 2002-04-04  2:35 UTC (permalink / raw)
  To: gcc-bugs, gcc-prs, jeroenk, nobody

Synopsis: Unsigned division bug in gcc 3.x

State-Changed-From-To: open->closed
State-Changed-By: rth
State-Changed-When: Thu Apr  4 02:35:25 2002
State-Changed-Why:
    (1) You did not provide the target tuple.  I'm presuming
        i686-linux, since that's what most people who forget
        that linux runs on stuff besides x86 mean.
    (2) You did not provide the compiler options to use in
        reproducing your bug.  I tried -O0, -O1, and -O2.
    
    And I can't reproduce this with 3.1 20020326, so I presume its fixed.

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=6170


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

end of thread, other threads:[~2002-04-04 10:35 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-04-04  2:06 c/6170: Unsigned division bug in gcc 3.x jeroenk
2002-04-04  2:35 rth

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).