This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
regarding casting
- To: gcc-patches at gcc dot gnu dot org
- Subject: regarding casting
- From: Chandra Chavva <cchavva at cygnus dot com>
- Date: Fri, 11 Feb 2000 14:47:24 -0800 (PST)
Hi,
The gcc is generating wrong code when int is casted to short and
assigned to short. This is happening for mips instruction generated
code. I noticed this in 103125-CR-1 for target mips64r5900-sky-elf.
Here is the test case
#include <stdio.h>
int Test(int p)
{
int i;
short s = p;
for (i = 0; i < 4; i++) {
s += 2;
s += 2;
}
return (int)s;
}
int main()
{
printf("%d\n", Test(0));
}
Here is the patch, please let me know if this is correct or not. This
patch also applies to egcs sources.
Index: ChangeLog
===================================================================
RCS file: /cvs/cvsfiles/devo/gcc/ChangeLog,v
retrieving revision 1.4631.2.48
diff -p -r1.4631.2.48 ChangeLog
*** ChangeLog 1999/12/16 17:06:31 1.4631.2.48
--- ChangeLog 2000/02/11 22:46:25
***************
*** 1,3 ****
--- 1,8 ----
+ Wed Feb 11 12:04:58 2000 Chandra Chavva <cchavva@cygnus.com>
+
+ * loop.c (basic_induction_var): Fixed the code generation for
+ casting int to short.
+
Fri Dec 10 13:49:12 1999 Andrew Haley <aph@cygnus.com>
* jump.c (delete_insn): When deleting a CALL_PLACEHOLDER, make
Index: loop.c
===================================================================
RCS file: /cvs/cvsfiles/devo/gcc/loop.c,v
retrieving revision 1.197.4.4
diff -p -r1.197.4.4 loop.c
*** loop.c 1999/11/11 15:45:43 1.197.4.4
--- loop.c 2000/02/11 22:20:31
*************** basic_induction_var (x, mode, dest_reg,
*** 5987,5993 ****
&& GET_CODE (XEXP (x, 1)) == CONST_INT
&& INTVAL (XEXP (x, 1)) >= 0
&& GET_CODE (SET_SRC (set)) == ASHIFT
! && XEXP (x, 1) == XEXP (SET_SRC (set), 1))
return basic_induction_var (XEXP (SET_SRC (set), 0),
GET_MODE (XEXP (x, 0)),
dest_reg, insn, inc_val, mult_val,
--- 5987,5994 ----
&& GET_CODE (XEXP (x, 1)) == CONST_INT
&& INTVAL (XEXP (x, 1)) >= 0
&& GET_CODE (SET_SRC (set)) == ASHIFT
! && XEXP (x, 1) == XEXP (SET_SRC (set), 1)
! && SET_DEST(set) == dest_reg)
return basic_induction_var (XEXP (SET_SRC (set), 0),
GET_MODE (XEXP (x, 0)),
dest_reg, insn, inc_val, mult_val,