This is the mail archive of the gcc-bugs@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]

c/3651: shifting unsigned long on 64 bit machine incorrectly does sign extension



>Number:         3651
>Category:       c
>Synopsis:       shifting unsigned long on 64 bit machine incorrectly does sign extension
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed Jul 11 12:16:00 PDT 2001
>Closed-Date:
>Last-Modified:
>Originator:     mark.dewing@intel.com
>Release:        gcc version 3.0 20010526 (prerelease)
>Organization:
>Environment:
IA64 Turbolinux
>Description:
Right shifting an unsigned long should not do a sign
extension.  This shift on an unsigned long variable works
okay, but doing this shift on an expression that has
been cast to unsigned long does not.
This problem also occurs on Alpha Tru64 with gcc 2.7.2.1
and IRIX with gcc 2.8.1 in 64 bit mode.
>How-To-Repeat:

>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:
----gnatsweb-attachment----
Content-Type: text/plain; name="shift-gcc.c"
Content-Disposition: inline; filename="shift-gcc.c"


#include <stdio.h>
main(){
int i,j;
unsigned long u,r1,r2;

 i = -16;
 j = 1;
 u = i+j;

 /* no sign extension upon shift */
 r1 = u >> 1;
 /* sign extension upon shift, but there shouldn't be */
 r2 = ( (unsigned long) (i+j) ) >> 1;
 printf(" r1 = %lx\n",r1);
 printf(" r2 = %lx\n",r2);
 
}


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