This is the mail archive of the
gcc-prs@gcc.gnu.org
mailing list for the GCC project.
c/7284: incorrectly simplifies leftshift followed by signed power-of-2 division
- From: algrant at acm dot org
- To: gcc-gnats at gcc dot gnu dot org
- Date: 12 Jul 2002 11:25:26 -0000
- Subject: c/7284: incorrectly simplifies leftshift followed by signed power-of-2 division
- Reply-to: algrant at acm dot org
>Number: 7284
>Category: c
>Synopsis: incorrectly simplifies leftshift followed by signed power-of-2 division
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: wrong-code
>Submitter-Id: net
>Arrival-Date: Fri Jul 12 04:26:00 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator: Al Grant
>Release: 3.1
>Organization:
>Environment:
SunOS 5.5.1 Generic_103640-31 sun4u sparc SUNW,Ultra-5_10
>Description:
Incorrect simplification of signed
(n << 24) / (1 << 23)
to a single left shift. Should sign-extend from bit 8.
>How-To-Repeat:
#include <stdio.h>
int f(int n) { return (n<<24) / (1<<23); }
int main(void) {
if (f(128) != -256) printf("Broken\n"); return 0; }
>Fix:
Replace with left shift followed by signed right shift.
This can be done in source as a workaround.
>Release-Note:
>Audit-Trail:
>Unformatted: