Skip to content

Commit

Permalink
CTFE: don't modify string literals passed by ref
Browse files Browse the repository at this point in the history
Fixes bug found by Stephan Dilly. We need to resolve slices before duping,
otherwise copyLiteral doesn't work.
  • Loading branch information
Don Clugston committed Jul 8, 2011
1 parent 47efdef commit 1631f47
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/interpret.c
Expand Up @@ -2997,14 +2997,15 @@ Expression *BinExp::interpretAssignCommon(InterState *istate, CtfeGoal goal, fp_
Expression * newval = NULL;

if (!wantRef)
// We need to treat pointers specially, because TOKsymoff can be used to
{ // We need to treat pointers specially, because TOKsymoff can be used to
// return a value OR a pointer
assert(e1);
assert(e1->type);
if ((e1->type->ty == Tpointer && e1->type->nextOf()->ty != Tfunction) && (e2->op == TOKsymoff || e2->op==TOKaddress || e2->op==TOKvar)) // && (e1->op==TOKaddress)) //TOKsymoff || e1->op==TOKdotvar))
newval = this->e2->interpret(istate, ctfeNeedLvalue);
else
newval = this->e2->interpret(istate);
}
if (newval == EXP_CANT_INTERPRET)
return newval;
// ----------------------------------------------------
Expand Down Expand Up @@ -3969,6 +3970,8 @@ Expression *CallExp::interpret(InterState *istate, CtfeGoal goal)
e = e->interpret(istate);
if (e != EXP_CANT_INTERPRET)
{
if (e->op == TOKslice)
e= resolveSlice(e);
e = expType(type, e);
e = copyLiteral(e);
}
Expand Down

0 comments on commit 1631f47

Please sign in to comment.