This is the mail archive of the gcc-prs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

c/7284: incorrectly simplifies leftshift followed by signed power-of-2 division


>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:


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]