Bug un tableswitch

Maxim Kizub max at immsp.kiev.ua
Tue Jan 26 06:31:58 PST 1999


Parmelan, Edouard wrote:
> 
> Hi,
> 
> > public class Test {
> >
> >         public static void main(String[] args) {
> >                 int i = 0x7fffffff;
> >                 System.out.println("switch("+i+")");
> >                 switch(i) {
> >                 case -1: System.out.println("-1"); break;
> >                 case 0: System.out.println("0"); break;
> >                 case 1: System.out.println("1"); break;
> >                 default: System.out.println("default"); break;
> >                 }
> >         }
> >
> > }
> >
> > > javac Test.java
> > > java Test
> > switch(2147483647)
> > default
> >
> > > kaffe Test
> > switch(2147483647)
> > -1
> >
> >
> > There's something wring in tableswitch generation.
> Yep, and it's not ix86 but any arch :(
> >From kaffe.def, TABLESWITCH:
>         cbranch_int_const_lt(stack(0), low, reference_label(TABLESWITCH,
> 8));
>         if (low != 0) {
>                 start_sub_block();
>                 sub_int_const(stack(0), stack(0), low);
>                 end_sub_block();
>         }
>         cbranch_int_const_le(stack(0), high-low,
> reference_label(TABLESWITCH, 7));
> 
> stack(0) = i == 0x7FFFFFFF
> low = -1, high = 1
> sub_int_const(stack(0), stack(0), low) == 0x7FFFFFFF - -1
>   == 0x80000000 == -1
> but -1 <= high-low :(
> 
> May be we sould use an unsigned compare function ?


Maybe, it's better to have 
cbranch_int_const_lt(stack(0), low, reference_label(TABLESWITCH, 8));
cbranch_int_const_gt(stack(0), high, reference_label(TABLESWITCH, 8));

before substitution of 'low'?

Also, I did asked, but nobody answered me -
what are start/end_sub_block() makroses?
what are slot_alloctmp() and slot_freetmp()?
Why, aftre slot_freetmp() kaffe still stores
my tmp value in stack?
Also, I can't understand rules of using
labels in kaffe codegenerator...

The code I've wrote for new bytecodes works
somehow, but _I_do_not_understand_what_I_do_!!!

Regards
  Maxim Kizub




More information about the kaffe mailing list