Skip to content

Commit

Permalink
Evaluation order is LTR
Browse files Browse the repository at this point in the history
  • Loading branch information
jpf91 committed Apr 1, 2014
1 parent 2d4dd77 commit 5bc609b
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 22 deletions.
7 changes: 7 additions & 0 deletions gcc/d/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
2014-04-01 Johannes Pfau <johannespfau@gmail.com>

* d-codegen.cc(d_build_call): Evaluate extern(C) functions LTR just
like extern(D) functions.
* d-elem.cc(AssignExp::toElem): Evaluate assignments LTR if both sides
have side effects.

2014-03-31 Iain Buclaw <ibuclaw@gdcproject.org>

* d-codegen.cc(error_mark_p): Removed function, replace uses with
Expand Down
2 changes: 1 addition & 1 deletion gcc/d/d-codegen.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2037,7 +2037,7 @@ d_build_call (TypeFunction *tf, tree callable, tree object, Expressions *argumen

// Evaluate the argument before passing to the function.
// Needed for left to right evaluation.
if (tf->linkage == LINKd && TREE_SIDE_EFFECTS (targ))
if (TREE_SIDE_EFFECTS (targ))
{
targ = maybe_make_temp (targ);
saved_args = maybe_vcompound_expr (saved_args, targ);
Expand Down
16 changes: 14 additions & 2 deletions gcc/d/d-elem.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1094,9 +1094,21 @@ AssignExp::toElem (IRState *irs)
return result;
}

tree te1 = e1->toElem (irs);
tree te2 = convert_for_assignment (e2->toElem (irs), e2->type, e1->type);
tree saved_args = NULL_TREE;
if (TREE_SIDE_EFFECTS (te1) && TREE_SIDE_EFFECTS (te2))
{
te1 = stabilize_reference (te1);
saved_args = maybe_vcompound_expr (saved_args, te1);

te2 = maybe_make_temp (te2);
saved_args = maybe_vcompound_expr (saved_args, te2);
}

// Simple assignment
return modify_expr (type->toCtype(), e1->toElem (irs),
convert_for_assignment (e2->toElem (irs), e2->type, e1->type));
tree result = modify_expr (type->toCtype(), te1, te2);
return maybe_compound_expr (saved_args, result);
}

elem *
Expand Down
38 changes: 19 additions & 19 deletions gcc/d/dfrontend/arrayop.c
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ Expression *BinAssignExp::arrayOp(Scope *sc)
void Expression::buildArrayIdent(OutBuffer *buf, Expressions *arguments)
{
buf->writestring("Exp");
arguments->shift(this);
arguments->push(this);
}

void CastExp::buildArrayIdent(OutBuffer *buf, Expressions *arguments)
Expand All @@ -461,30 +461,30 @@ void CastExp::buildArrayIdent(OutBuffer *buf, Expressions *arguments)
void ArrayLiteralExp::buildArrayIdent(OutBuffer *buf, Expressions *arguments)
{
buf->writestring("Slice");
arguments->shift(this);
arguments->push(this);
}

void SliceExp::buildArrayIdent(OutBuffer *buf, Expressions *arguments)
{
buf->writestring("Slice");
arguments->shift(this);
arguments->push(this);
}

void AssignExp::buildArrayIdent(OutBuffer *buf, Expressions *arguments)
{
/* Evaluate assign expressions right to left
/* Evaluate assign expressions left to right
*/
e2->buildArrayIdent(buf, arguments);
e1->buildArrayIdent(buf, arguments);
e2->buildArrayIdent(buf, arguments);
buf->writestring("Assign");
}

void BinAssignExp::buildArrayIdent(OutBuffer *buf, Expressions *arguments)
{
/* Evaluate assign expressions right to left
/* Evaluate assign expressions left to right
*/
e2->buildArrayIdent(buf, arguments);
e1->buildArrayIdent(buf, arguments);
e2->buildArrayIdent(buf, arguments);
const char *s;
switch(op)
{
Expand Down Expand Up @@ -518,7 +518,7 @@ void ComExp::buildArrayIdent(OutBuffer *buf, Expressions *arguments)

void BinExp::buildArrayIdent(OutBuffer *buf, Expressions *arguments)
{
/* Evaluate assign expressions left to right
/* Evaluate array op expressions left to right
*/
const char *s = NULL;
switch(op)
Expand Down Expand Up @@ -555,7 +555,7 @@ Expression *Expression::buildArrayLoop(Parameters *fparams)
{
Identifier *id = Identifier::generateId("c", fparams->dim);
Parameter *param = new Parameter(0, type, id, NULL);
fparams->shift(param);
fparams->push(param);
Expression *e = new IdentifierExp(Loc(), id);
return e;
}
Expand All @@ -575,7 +575,7 @@ Expression *ArrayLiteralExp::buildArrayLoop(Parameters *fparams)
{
Identifier *id = Identifier::generateId("p", fparams->dim);
Parameter *param = new Parameter(STCconst, type, id, NULL);
fparams->shift(param);
fparams->push(param);
Expression *e = new IdentifierExp(Loc(), id);
Expressions *arguments = new Expressions();
Expression *index = new IdentifierExp(Loc(), Id::p);
Expand All @@ -588,7 +588,7 @@ Expression *SliceExp::buildArrayLoop(Parameters *fparams)
{
Identifier *id = Identifier::generateId("p", fparams->dim);
Parameter *param = new Parameter(STCconst, type, id, NULL);
fparams->shift(param);
fparams->push(param);
Expression *e = new IdentifierExp(Loc(), id);
Expressions *arguments = new Expressions();
Expression *index = new IdentifierExp(Loc(), Id::p);
Expand All @@ -599,8 +599,11 @@ Expression *SliceExp::buildArrayLoop(Parameters *fparams)

Expression *AssignExp::buildArrayLoop(Parameters *fparams)
{
/* Evaluate assign expressions right to left
/* Evaluate assign expressions left to right
*/
Expression *ex1 = e1->buildArrayLoop(fparams);
Parameter *param = (*fparams)[fparams->dim - 1];
param->storageClass = 0;
Expression *ex2 = e2->buildArrayLoop(fparams);
#if DMDV2
/* Need the cast because:
Expand All @@ -610,21 +613,18 @@ Expression *AssignExp::buildArrayLoop(Parameters *fparams)
*/
ex2 = new CastExp(Loc(), ex2, e1->type->nextOf());
#endif
Expression *ex1 = e1->buildArrayLoop(fparams);
Parameter *param = (*fparams)[0];
param->storageClass = 0;
Expression *e = new AssignExp(Loc(), ex1, ex2);
return e;
}

Expression *BinAssignExp::buildArrayLoop(Parameters *fparams)
{
/* Evaluate assign expressions right to left
/* Evaluate assign expressions left to right
*/
Expression *ex2 = e2->buildArrayLoop(fparams);
Expression *ex1 = e1->buildArrayLoop(fparams);
Parameter *param = (*fparams)[0];
Parameter *param = (*fparams)[fparams->dim - 1];
param->storageClass = 0;
Expression *ex2 = e2->buildArrayLoop(fparams);
Expression *e;
switch(op)
{
Expand Down Expand Up @@ -675,7 +675,7 @@ Expression *BinExp::buildArrayLoop(Parameters *fparams)
case TOKpow:
#endif
{
/* Evaluate assign expressions left to right
/* Evaluate array op expressions left to right
*/
BinExp *e = (BinExp *)copy();
e->e1 = e->e1->buildArrayLoop(fparams);
Expand Down

0 comments on commit 5bc609b

Please sign in to comment.