This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: problem building a GCJ-friendly GNU Crypto


Hi Mark,
> On Fri, 2003-09-19 at 16:37, Roger Sayle wrote:
> > A reduced test case would be great.
>
> The following should give:
> XO: 1
> But (with your patch applied) gives:
> X0: 65536.
>
> public class ConstTest
> {
>   public static void main(String[] args)
>   {
>     byte[] in = new byte[] { 1, 0, 0, 0 };
>     int i = 0;
>     int X0 =  (in[i++] & 0xFF)
>             | (in[i++] & 0xFF) << 8
>             | (in[i++] & 0xFF) << 16
>             | in[i++] << 24;
>     System.out.println("X0: " + X0);
>   }
> }

Thanks for the test case.  Looking at it I can immediately guess what
the problem is: the evaluation order of operands to binary operators.
A quick check of section 15.7.1 of the Java language specification
reveals that the semantics are indeed different from C and C++s which
allow side-effecting operands to be evaluated in arbitrary order.

I'm currently working on a patch to add an -fevaluation-order command
line option to GCC, that sets a flag_evaluation_order variable that
can be checked during constant folding to preserve left-to-right
evaluation order of binary expressions.  This can then be enabled by
default  by the java front-end, which should help make libbackend.a
more java friendly.

In the mean-time, the obvious fix is in[i], in[i+1], in[i+2] etc...
as recommended in section 15.7 in the java language specs.  Hopefully,
I'll have a patch to fix the real problem ready to submit in a day
or two.  Sorry for the inconvenience.

Roger
--
Roger Sayle,                         E-mail: roger@eyesopen.com
OpenEye Scientific Software,         WWW: http://www.eyesopen.com/
Suite 1107, 3600 Cerrillos Road,     Tel: (+1) 505-473-7385
Santa Fe, New Mexico, 87507.         Fax: (+1) 505-473-0833


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