JAVA: byte compiler fixes
Andrew Haley
aph@cygnus.co.uk
Wed Aug 23 07:25:00 GMT 2000
In a couple places we assume that we can truncate to a 32-bit value by
casting. Well, maybe we can, but in the context of a cross compiler
it doesn't make sense to assume that host and target integer types are
compatible and it's difficult without a lot of configury to guarantee
that they will be. This patch makes truncation and sign extension
explicit.
Fixes gcj/321.
Andrew.
2000-08-22 Andrew Haley <aph@cygnus.com>
* javaop.h (WORD_TO_INT): Mask lower 32 bits of a jword before
sign extending.
* jcf-parse.c (get_constant): Mask lower 32 bits of a jint before
combining to make a jlong.
Index: javaop.h
===================================================================
RCS file: /cvs/cvsfiles/devo/gcc/java/javaop.h,v
retrieving revision 1.12
diff -c -2 -p -r1.12 javaop.h
*** javaop.h 2000/05/15 17:56:05 1.12
--- javaop.h 2000/08/23 14:06:51
*************** WORD_TO_FLOAT(jword w)
*** 110,120 ****
}
! /* Sign extend w. */
static inline jint
WORD_TO_INT(jword w)
{
! jint n = w;
n ^= (jint)1 << 31;
! n -= (jint)1 << 31;
return n;
}
--- 110,123 ----
}
! /* Sign extend w. If the host on which this cross-compiler runs uses
! a 64-bit type for jword the appropriate sign extension is
! performed; if it's a 32-bit type the arithmetic does nothing but is
! harmless. */
static inline jint
WORD_TO_INT(jword w)
{
! jint n = w & 0xffffffff; /* Mask lower 32 bits. */
n ^= (jint)1 << 31;
! n -= (jint)1 << 31; /* Sign extend lower 32 bits to upper. */
return n;
}
Index: jcf-parse.c
===================================================================
RCS file: /cvs/cvsfiles/devo/gcc/java/jcf-parse.c,v
retrieving revision 1.68
diff -c -2 -p -r1.68 jcf-parse.c
*** jcf-parse.c 2000/07/14 17:50:59 1.68
--- jcf-parse.c 2000/08/23 14:06:23
*************** get_constant (jcf, index)
*** 272,277 ****
HOST_WIDE_INT lo, hi;
lshift_double (num, 0, 32, 64, &lo, &hi, 0);
! num = JPOOL_INT (jcf, index+1);
! add_double (lo, hi, (uint32)num, 0, &lo, &hi);
value = build_int_2 (lo, hi);
TREE_TYPE (value) = long_type_node;
--- 272,277 ----
HOST_WIDE_INT lo, hi;
lshift_double (num, 0, 32, 64, &lo, &hi, 0);
! num = JPOOL_INT (jcf, index+1) & 0xffffffff;
! add_double (lo, hi, num, 0, &lo, &hi);
value = build_int_2 (lo, hi);
TREE_TYPE (value) = long_type_node;
More information about the Gcc-patches
mailing list