Problem with hard-coded register variables

Sun Dec 12 05:25:00 GMT 1999

When inlining a function which uses hard-coded register variables,
inside another function which hard-codes another variable in the same
register, code that saves and restores the outer variable is not

The test program (which uses x86 registers):

    #include <stdio.h>
    inline void test ()
      register int b asm("%edi");
      b = 5;
      printf("inside %d\n", b);
    int main ()
      register int a asm("%edi");
      a = 1;
      printf("outside %d\n", a);
      test ();
      printf("outside %d\n", a);
      exit (a != 1);

    outside 1
    inside 5
    outside 1

(correct) with inlining disabled, and
    outside 1
    inside 5
    outside 5

(wrong) with inlining enabled.

gcc -v shows:
    Reading specs from
    gcc driver version 2.7-B19 executing gcc version 2.7-97r2aBeta

gcc --version shows:

I don't know if the results apply to EGCS or GCC 2.95 compilers.

Paolo Bonzini

More information about the Gcc-bugs mailing list