From: Jae J Won (int177c@aurora.cc.monash.edu.au)
Date: 10/01/92


From: int177c@aurora.cc.monash.edu.au (Jae J Won)
Subject: gcc weirdness
Date: 2 Oct 1992 02:59:24 GMT

Hi,

        While working with gcc2.2.2d with jump table, I found a weirdness I really
couldn't pinpoint. Okay, what happens is that, when I run this code below
(okay, stop laughing at the code. The fact that code doesn't work properly
is not the question..:) , it somehow falls into an infinite loop. I have taken
the exact same code to the compiler(gcc, and cc) at my school's decs and they
work fine(sorta..at least it doesn't fall into infinite loops...)
        I did run gdb on it and at the end of the code, gdb tells me something like
"pc function lost" something..(I really can't remember). Okay, there is probably
a subtle option that prevents this infinite loop or something..:) If there is
, please someone point me to the right direction. If it is a bug(god forbid),
umm..well...(I doubt it though).
        Okay, here is the code and my setup is kernel 0.97pl4(it has been running so
well that I saw no need to upgrade), X 2.0(could it be this??) and I got a
386 with no copro.

Thanks to those who are willing to help...:)

Jae

code:

======from here======

#include <stdio.h>

typedef struct equiv{
        int wrong;
        int right;
} EQUIV;

int eq_count;

void optimize(EQUIV eq_region[], int eq_no, int wrong, int right){
        int i;
        for ( i=eq_no; i<eq_count; i++ ){
                if ( eq_region[i].right == wrong ){
                        eq_region[i].right = right;
                        optimize(eq_region, i, eq_region[i].wrong, right);}
        }
}

void main(){
        EQUIV eq_region[5];
        int i;
        eq_count = 7;
        eq_region[0].wrong = 2 ; eq_region[0].right = 1 ;
        eq_region[1].wrong = 4 ; eq_region[1].right = 2 ;
        eq_region[2].wrong = 5 ; eq_region[2].right = 3 ;
        eq_region[3].wrong = 6 ; eq_region[3].right = 4 ;
        eq_region[4].wrong = 7 ; eq_region[4].right = 4 ;
        eq_region[5].wrong = 8 ; eq_region[5].right = 5 ;
        eq_region[6].wrong = 9 ; eq_region[6].right = 5 ;

        for (i=0; i<eq_count; i++){
                printf("eq_region[%d].wrong = %d ; eq_region[%d].right = %d\n" ,i, eq_region[i].wrong, i, eq_region[i].right);
        }
        optimize(eq_region, 0, eq_region[0].wrong, eq_region[0].right);
        printf("\n\nOptimized stuff\n");

        eq_count = 7;
        for (i=0; i<eq_count; i++){
                printf("eq_region[%d].wrong = %d ; eq_region[%d].right = %d\n" ,i, eq_region[i].wrong, i, eq_region[i].right);
        }
}