elnewfie / lslforge

Automatically exported from code.google.com/p/lslforge
24 stars 13 forks source link

pragma inline produces invalid code if used in do loop condition #66

Open Sei-Lisa opened 5 years ago

Sei-Lisa commented 5 years ago

When using // pragma inline in a function, and that function is used in the condition of a do...while loop, the generated code is invalid, because the condition uses a variable which is defined within the braces of the loop, therefore it's out of scope.

For example:

// pragma inline
integer f(integer i)
{
    if (i)
        return 0;
    return 2;
}

default
{
    state_entry()
    {
        do
        {
            llSleep(1);
        }
        while (f(llGetLinkNumber()));
    }
}

Generated code:

default {
  state_entry() {
    do {

      integer _ret1;
      integer i = llGetLinkNumber();
      if (i) {
        _ret1 = 0;
        jump _end2;
      }
      _ret1 = 2;
      @_end2;
    }
    while (_ret1); // Name not defined within scope (because it's out of scope)
  }
}

Thanks to Levio Serenity for the testing.