c/8224: Incorrect joining of signed and unsigned division

mikulas@artax.karlin.mff.cuni.cz mikulas@artax.karlin.mff.cuni.cz
Mon Oct 14 07:36:00 GMT 2002


>Number:         8224
>Category:       c
>Synopsis:       Incorrect joining of signed and unsigned division
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          wrong-code
>Submitter-Id:   net
>Arrival-Date:   Mon Oct 14 07:36:02 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator:     Mikulas Patocka
>Release:        gcc-2.7.2.3, gcc-2.95.4, gcc-3.0.4, gcc-3.2
>Organization:
>Environment:
Bug present in almost all gcc releases, tested on Linux and OS/2.
>Description:
When evaluating expressions like (unsigned)((int)x/2)/2,
gcc incorrectly merges these two divisions into one signed
(or unsigned in 2.7.2.3) division by 4, producing incorrect
result.
>How-To-Repeat:
Compile and run the file. The bug can be seen with or
without optimizations.
>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:
----gnatsweb-attachment----
Content-Type: application/octet-stream; name="bug-div.c"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="bug-div.c"

dW5zaWduZWQgZihpbnQgeCkNCnsNCglyZXR1cm4gKHVuc2lnbmVkKSgoaW50KXgvMikvMjsNCn0N
Cg0KdW5zaWduZWQgZjEoaW50IHgpDQp7DQoJdW5zaWduZWQgeHggPSB4LzI7DQoJcmV0dXJuIHh4
LzI7DQp9DQoNCm1haW4oKQ0Kew0KCXByaW50ZigiJWQgLSAlMDh4XG4iLCAtNSwgZjEoLTUpKTsN
CglwcmludGYoIiVkIC0gJTA4eFxuIiwgLTUsIGYoLTUpKTsNCglyZXR1cm4gMDsNCn0NCg==



More information about the Gcc-bugs mailing list