Skip to content

Commit

Permalink
Add VectorExp handling in CTFE interpreter to fix compilable/test8543.d
Browse files Browse the repository at this point in the history
  • Loading branch information
9rnsr committed Dec 2, 2014
1 parent 91e6e87 commit ada7e9c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/constfold.c
Expand Up @@ -1175,6 +1175,13 @@ UnionExp Cast(Type *type, Type *to, Expression *e1)
return ue;
}

if (e1->op == TOKvector && ((TypeVector *)e1->type)->basetype->equals(type) && type->equals(to))
{
Expression *ex = ((VectorExp *)e1)->e1;
memcpy(&ue, ex, ex->size);
return ue;
}

if (e1->type->implicitConvTo(to) >= MATCHconst ||
to->implicitConvTo(e1->type) >= MATCHconst)
{
Expand Down
3 changes: 3 additions & 0 deletions src/ctfeexpr.c
Expand Up @@ -446,6 +446,9 @@ Expression *resolveSlice(Expression *e)
*/
uinteger_t resolveArrayLength(Expression *e)
{
if (e->op == TOKvector)
e = ((VectorExp *)e)->e1;

if (e->op == TOKnull)
return 0;
if (e->op == TOKslice)
Expand Down
7 changes: 6 additions & 1 deletion src/interpret.c
Expand Up @@ -3787,6 +3787,8 @@ class Interpreter : public Visitor
/* Assignment to variable of the form:
* v = newval
*/
if (e1->op == TOKvector)
e1 = ((VectorExp *)e1)->e1;
if (e1->op == TOKvar)
{
VarExp *ve = (VarExp *)e1;
Expand Down Expand Up @@ -4009,6 +4011,7 @@ class Interpreter : public Visitor
return false;
}
if (oldval->op != TOKarrayliteral &&
oldval->op != TOKvector &&
oldval->op != TOKstring &&
oldval->op != TOKslice)
{
Expand Down Expand Up @@ -4134,6 +4137,8 @@ class Interpreter : public Visitor
}
if (aggregate->op == TOKarrayliteral)
existingAE = (ArrayLiteralExp *)aggregate;
else if (aggregate->op == TOKvector)
existingAE = (ArrayLiteralExp *)((VectorExp *)aggregate)->e1;
else if (aggregate->op == TOKstring)
existingSE = (StringExp *)aggregate;
else
Expand Down Expand Up @@ -6172,7 +6177,7 @@ class Interpreter : public Visitor
if (result->op == TOKstructliteral)
return;
if ((e->type->ty == Tsarray || goal == ctfeNeedLvalue) && (
result->op == TOKarrayliteral ||
result->op == TOKarrayliteral || result->op == TOKvector ||
result->op == TOKassocarrayliteral || result->op == TOKstring ||
result->op == TOKclassreference || result->op == TOKslice))
{
Expand Down

0 comments on commit ada7e9c

Please sign in to comment.