Fix bug where the compiler could crash trying to dereference a decayed accessor expression used as |this|.

This commit is contained in:
David Anderson 2015-04-12 18:12:05 -04:00 committed by Nicholas Hastings
parent d64bcc763a
commit 15b65468ac
3 changed files with 13 additions and 1 deletions

View File

@ -733,6 +733,7 @@ void startfunc(char *fname);
void endfunc(void);
void alignframe(int numbytes);
void rvalue(value *lval);
void rvalue(svalue *sval);
void address(symbol *ptr,regid reg);
void store(value *lval);
void loadreg(cell address,regid reg);

View File

@ -2784,7 +2784,8 @@ static int nesting=0;
// this reduces it to an iEXPRESSION. That's ok. We don't touch it
// otherwise though, so the type checking logic below basically acts the
// same. We are careful to not double-evaluate however.
rvalue(&implicit_this.val);
if (implicit_this.lvalue)
rvalue(&implicit_this);
pushreg(sPRI);
nest_stkusage++;
}

View File

@ -426,6 +426,16 @@ void rvalue(value *lval)
} /* if */
}
// Wrapper that automatically markes lvalues as decayed if they are accessors,
// since it is illegal to evaluate them twice.
void rvalue(svalue *sval)
{
int ident = sval->val.ident;
rvalue(&sval->val);
if (ident == iACCESSOR)
sval->lvalue = FALSE;
}
/* Get the address of a symbol into the primary or alternate register (used
* for arrays, and for passing arguments by reference).
*/