From: Roger Sayle Date: Mon, 24 Jan 2005 14:34:19 +0000 (+0000) Subject: re PR java/19295 (Incorrect bytecode produced for bitwise AND) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=d5f625555adfef72898749680608b2570a6cb293;p=gcc.git re PR java/19295 (Incorrect bytecode produced for bitwise AND) PR java/19295 * jcf-write.c (generate_bytecode_insns): Conversions between integer types of the same precision shouldn't generate widening or narrowing conversion bytecodes. * testsuite/libjava.compile/PR19295.java: New test case. From-SVN: r94162 --- diff --git a/gcc/java/ChangeLog b/gcc/java/ChangeLog index f9927d8865b..cf7810c4278 100644 --- a/gcc/java/ChangeLog +++ b/gcc/java/ChangeLog @@ -1,3 +1,10 @@ +2005-01-24 Roger Sayle + + PR java/19295 + * jcf-write.c (generate_bytecode_insns): Conversions between + integer types of the same precision shouldn't generate widening + or narrowing conversion bytecodes. + 2005-01-22 Kazu Hirata * java-except.h, java-tree.h: Remove unused prototypes. diff --git a/gcc/java/jcf-write.c b/gcc/java/jcf-write.c index 8b6dc7de328..da8c6c99870 100644 --- a/gcc/java/jcf-write.c +++ b/gcc/java/jcf-write.c @@ -2260,40 +2260,48 @@ generate_bytecode_insns (tree exp, int target, struct jcf_partial *state) } else /* Convert numeric types. */ { - int wide_src = TYPE_PRECISION (src_type) > 32; - int wide_dst = TYPE_PRECISION (dst_type) > 32; - NOTE_POP (1 + wide_src); - RESERVE (1); + int src_prec = TYPE_PRECISION (src_type); + int dst_prec = TYPE_PRECISION (dst_type); + int wide_src = src_prec > 32; + int wide_dst = dst_prec > 32; if (TREE_CODE (dst_type) == REAL_TYPE) { + NOTE_POP (1 + wide_src); + RESERVE (1); if (TREE_CODE (src_type) == REAL_TYPE) OP1 (wide_dst ? OPCODE_f2d : OPCODE_d2f); - else if (TYPE_PRECISION (src_type) == 64) + else if (src_prec == 64) OP1 (OPCODE_l2f + wide_dst); else OP1 (OPCODE_i2f + wide_dst); + NOTE_PUSH (1 + wide_dst); } - else /* Convert to integral type. */ + /* Convert to integral type (but ignore non-widening + and non-narrowing integer type conversions). */ + else if (TREE_CODE (src_type) == REAL_TYPE + || src_prec != dst_prec) { + NOTE_POP (1 + wide_src); + RESERVE (1); if (TREE_CODE (src_type) == REAL_TYPE) OP1 (OPCODE_f2i + wide_dst + 3 * wide_src); else if (wide_dst) OP1 (OPCODE_i2l); else if (wide_src) OP1 (OPCODE_l2i); - if (TYPE_PRECISION (dst_type) < 32) + if (dst_prec < 32) { RESERVE (1); /* Already converted to int, if needed. */ - if (TYPE_PRECISION (dst_type) <= 8) + if (dst_prec <= 8) OP1 (OPCODE_i2b); else if (TYPE_UNSIGNED (dst_type)) OP1 (OPCODE_i2c); else OP1 (OPCODE_i2s); } + NOTE_PUSH (1 + wide_dst); } - NOTE_PUSH (1 + wide_dst); } } break; diff --git a/libjava/ChangeLog b/libjava/ChangeLog index 5bab10489d6..86447b92f4c 100644 --- a/libjava/ChangeLog +++ b/libjava/ChangeLog @@ -1,3 +1,8 @@ +2005-01-24 Roger Sayle + + PR java/19295 + * testsuite/libjava.compile/PR19295.java: New test case. + 2005-01-19 Tom Tromey * java/lang/VMCompiler.java (compileClass): Ignore UnknownError. diff --git a/libjava/testsuite/libjava.compile/PR19295.java b/libjava/testsuite/libjava.compile/PR19295.java new file mode 100644 index 00000000000..336f7e9863b --- /dev/null +++ b/libjava/testsuite/libjava.compile/PR19295.java @@ -0,0 +1,16 @@ +public class PR19295 implements myInterface { + public long tagBits = 0; + + public final boolean isArrayType() { + return (tagBits & IsArrayType) != 0; + } +} + +abstract class blah { + public final static int Bit1 = 0x2; +} + +interface myInterface { + long IsArrayType = blah.Bit1; +} +