Skip to content

Commit

Permalink
Merge branch 'merge_stable_convert' into merge_stable
Browse files Browse the repository at this point in the history
Conflicts:
	src/access.d
	src/aggregate.d
	src/aliasthis.d
	src/apply.d
	src/argtypes.d
	src/arrayop.d
	src/arraytypes.d
	src/attrib.d
	src/builtin.d
	src/canthrow.d
	src/clone.d
	src/cond.d
	src/constfold.d
	src/cppmangle.d
	src/ctfeexpr.d
	src/dcast.d
	src/dclass.d
	src/declaration.d
	src/delegatize.d
	src/denum.d
	src/dimport.d
	src/dinterpret.d
	src/dmacro.d
	src/dmangle.d
	src/dmodule.d
	src/doc.d
	src/dscope.d
	src/dstruct.d
	src/dsymbol.d
	src/dtemplate.d
	src/dversion.d
	src/errors.d
	src/escape.d
	src/expression.d
	src/func.d
	src/globals.d
	src/hdrgen.d
	src/identifier.d
	src/init.d
	src/inline.d
	src/json.d
	src/lexer.d
	src/lib.d
	src/link.d
	src/mars.d
	src/mtype.d
	src/nogc.d
	src/nspace.d
	src/objc.d
	src/opover.d
	src/optimize.d
	src/parse.d
	src/root/file.d
	src/root/man.d
	src/root/outbuffer.d
	src/sapply.d
	src/sideeffect.d
	src/statement.d
	src/staticassert.d
	src/target.d
	src/tokens.d
	src/traits.d
	src/visitor.d
  • Loading branch information
MartinNowak committed Sep 7, 2015
2 parents 1445df5 + ff3f31b commit db14c61
Show file tree
Hide file tree
Showing 11 changed files with 462 additions and 122 deletions.
14 changes: 12 additions & 2 deletions src/backend/cod2.c
Original file line number Diff line number Diff line change
Expand Up @@ -5076,9 +5076,14 @@ code *cddctor(elem *e,regm_t *pretregs)
*/
usednteh |= EHcleanup;
if (config.exe == EX_NT)
{ usednteh |= NTEHcleanup | NTEH_try;
{
usednteh |= NTEHcleanup | NTEH_try;
nteh_usevars();
}
else
{
usednteh |= EHtry;
}
assert(*pretregs == 0);
code cs;
cs.Iop = ESCAPE | ESCdctor;
Expand Down Expand Up @@ -5114,9 +5119,14 @@ code *cdddtor(elem *e,regm_t *pretregs)
*/
usednteh |= EHcleanup;
if (config.exe == EX_NT)
{ usednteh |= NTEHcleanup | NTEH_try;
{
usednteh |= NTEHcleanup | NTEH_try;
nteh_usevars();
}
else
{
usednteh |= EHtry;
}

code cs;
cs.Iop = ESCAPE | ESCddtor;
Expand Down
2 changes: 2 additions & 0 deletions src/clone.d
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,8 @@ extern (C++) bool needToHash(StructDeclaration sd)
TypeStruct ts = cast(TypeStruct)tv;
if (needToHash(ts.sym))
goto Lneed;
if (ts.sym.aliasthis) // Bugzilla 14948
goto Lneed;
}
}
Ldontneed:
Expand Down
4 changes: 2 additions & 2 deletions src/e2ir.c
Original file line number Diff line number Diff line change
Expand Up @@ -3307,12 +3307,12 @@ elem *toElem(Expression *e, IRState *irs)
{
elem *ec = toElem(ce->econd, irs);

elem *eleft = toElemDtor(ce->e1, irs);
elem *eleft = toElem(ce->e1, irs);
tym_t ty = eleft->Ety;
if (global.params.cov && ce->e1->loc.linnum)
eleft = el_combine(incUsageElem(irs, ce->e1->loc), eleft);

elem *eright = toElemDtor(ce->e2, irs);
elem *eright = toElem(ce->e2, irs);
if (global.params.cov && ce->e2->loc.linnum)
eright = el_combine(incUsageElem(irs, ce->e2->loc), eright);

Expand Down
89 changes: 89 additions & 0 deletions src/expression.d
Original file line number Diff line number Diff line change
Expand Up @@ -750,6 +750,7 @@ extern (C++) Expression resolveUFCS(Scope* sc, CallExp ce)
key = key.implicitCastTo(sc, taa.index);
if (key.checkValue())
return new ErrorExp();
semanticTypeInfo(sc, taa.index);
return new RemoveExp(loc, eleft, key);
}
}
Expand Down Expand Up @@ -10003,7 +10004,10 @@ public:
FuncDeclaration f = sd.aggDelete;
FuncDeclaration fd = sd.dtor;
if (!f)
{
semanticTypeInfo(sc, ts);
break;
}
/* Construct:
* ea = copy e1 to a tmp to do side effects only once
* eb = call destructor
Expand Down Expand Up @@ -11090,6 +11094,7 @@ public:
if (e2.type == Type.terror)
return new ErrorExp();
}
semanticTypeInfo(sc, taa);
type = taa.next;
break;
}
Expand Down Expand Up @@ -13722,6 +13727,10 @@ public:
error("array comparison type mismatch, %s vs %s", t1next.toChars(), t2next.toChars());
return new ErrorExp();
}
if ((t1.ty == Tarray || t1.ty == Tsarray) && (t2.ty == Tarray || t2.ty == Tsarray))
{
semanticTypeInfo(sc, t1.nextOf());
}
}
else if (t1.ty == Tstruct || t2.ty == Tstruct || (t1.ty == Tclass && t2.ty == Tclass))
{
Expand Down Expand Up @@ -13848,6 +13857,7 @@ public:
// Convert key to type of key
e1 = e1.implicitCastTo(sc, ta.index);
}
semanticTypeInfo(sc, ta.index);
// Return type is pointer to value
type = ta.nextOf().pointerTo();
break;
Expand Down Expand Up @@ -14195,6 +14205,17 @@ public:
printf("e1 : %s\n", e1.type.toChars());
printf("e2 : %s\n", e2.type.toChars());
}
/* Bugzilla 14696: If either e1 or e2 contain temporaries which need dtor,
* make them conditional.
* Rewrite:
* cond ? (__tmp1 = ..., __tmp1) : (__tmp2 = ..., __tmp2)
* to:
* (auto __cond = cond) ? (... __tmp1) : (... __tmp2)
* and replace edtors of __tmp1 and __tmp2 with:
* __tmp1->edtor --> __cond && __tmp1.dtor()
* __tmp2->edtor --> __cond || __tmp2.dtor()
*/
hookDtors(sc);
return this;
}

Expand Down Expand Up @@ -14233,6 +14254,74 @@ public:
return this;
}

void hookDtors(Scope* sc)
{
extern (C++) final class DtorVisitor : StoppableVisitor
{
alias visit = super.visit;
public:
Scope* sc;
CondExp ce;
VarDeclaration vcond;
bool isThen;

extern (D) this(Scope* sc, CondExp ce)
{
this.sc = sc;
this.ce = ce;
this.vcond = null;
}

void visit(Expression e)
{
//printf("(e = %s)\n", e->toChars());
}

void visit(DeclarationExp e)
{
VarDeclaration v = e.declaration.isVarDeclaration();
if (v && !v.noscope && !v.isDataseg())
{
if (v._init)
{
ExpInitializer ei = v._init.isExpInitializer();
if (ei)
ei.exp.accept(this);
}
if (v.edtor)
{
if (!vcond)
{
vcond = new VarDeclaration(ce.econd.loc, ce.econd.type, Identifier.generateId("__cond"), new ExpInitializer(ce.econd.loc, ce.econd));
vcond.storage_class |= STCtemp | STCctfe | STCvolatile;
vcond.semantic(sc);
Expression de = new DeclarationExp(ce.econd.loc, vcond);
de = de.semantic(sc);
Expression ve = new VarExp(ce.econd.loc, vcond);
ce.econd = Expression.combine(de, ve);
}
//printf("\t++v = %s, v->edtor = %s\n", v->toChars(), v->edtor->toChars());
Expression ve = new VarExp(vcond.loc, vcond);
if (isThen)
v.edtor = new AndAndExp(v.edtor.loc, ve, v.edtor);
else
v.edtor = new OrOrExp(v.edtor.loc, ve, v.edtor);
v.edtor = v.edtor.semantic(sc);
//printf("\t--v = %s, v->edtor = %s\n", v->toChars(), v->edtor->toChars());
}
}
}
}

scope DtorVisitor v = new DtorVisitor(sc, this);
//printf("+%s\n", toChars());
v.isThen = true;
walkPostorder(e1, v);
v.isThen = false;
walkPostorder(e2, v);
//printf("-%s\n", toChars());
}

void accept(Visitor v)
{
v.visit(this);
Expand Down
1 change: 1 addition & 0 deletions src/expression.h
Original file line number Diff line number Diff line change
Expand Up @@ -1476,6 +1476,7 @@ class CondExp : public BinExp
Expression *toLvalue(Scope *sc, Expression *e);
Expression *modifiableLvalue(Scope *sc, Expression *e);
Expression *toBoolean(Scope *sc);
void hookDtors(Scope *sc);

void accept(Visitor *v) { v->visit(this); }
};
Expand Down

0 comments on commit db14c61

Please sign in to comment.