From mboxrd@z Thu Jan 1 00:00:00 1970 From: mark.dewing@intel.com To: gcc-gnats@gcc.gnu.org Subject: c/3651: shifting unsigned long on 64 bit machine incorrectly does sign extension Date: Wed, 11 Jul 2001 12:16:00 -0000 Message-id: <20010711190917.14360.qmail@sourceware.cygnus.com> X-SW-Source: 2001-07/msg00309.html List-Id: >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 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); }