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 2, 2015
2 parents d44cda0 + e239a35 commit 66c6a93
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/e2ir.c
Expand Up @@ -2502,7 +2502,7 @@ elem *toElem(Expression *e, IRState *irs)
Type *ta = are->e1->type->toBasetype();

// which we do if the 'next' types match
if (ae->ismemset)
if (ae->ismemset & 1)
{
// Do a memset for array[]=v
//printf("Lpair %s\n", ae->toChars());
Expand Down Expand Up @@ -2692,7 +2692,7 @@ elem *toElem(Expression *e, IRState *irs)

/* Look for reference initializations
*/
if (ae->op == TOKconstruct && ae->e1->op == TOKvar)
if (ae->op == TOKconstruct && ae->e1->op == TOKvar && !(ae->ismemset & 2))
{
VarExp *ve = (VarExp *)ae->e1;
Declaration *s = ve->var;
Expand Down
18 changes: 13 additions & 5 deletions src/expression.d
Expand Up @@ -11339,7 +11339,9 @@ public:
extern (C++) class AssignExp : BinExp
{
public:
int ismemset; // !=0 if setting the contents of an array
// &1 != 0 if setting the contents of an array
// &2 != 0 if setting the content of ref variable
int ismemset;

/************************************************************/
/* op can be TOKassign, TOKconstruct, or TOKblit */
Expand Down Expand Up @@ -11629,6 +11631,12 @@ public:
{
//printf("[%s] change to init - %s\n", loc.toChars(), toChars());
op = TOKconstruct;
if (e1.op == TOKvar && (cast(VarExp)e1).var.storage_class & (STCout | STCref))
{
// Bugzilla 14944, even if e1 is a ref variable,
// make an initialization of referenced memory.
ismemset |= 2;
}
// Bugzilla 13515: set Index::modifiable flag for complex AA element initialization
if (e1.op == TOKindex)
{
Expand All @@ -11640,7 +11648,7 @@ public:
/* If it is an assignment from a 'foreign' type,
* check for operator overloading.
*/
if (op == TOKconstruct && e1.op == TOKvar && (cast(VarExp)e1).var.storage_class & (STCout | STCref))
if (op == TOKconstruct && e1.op == TOKvar && (cast(VarExp)e1).var.storage_class & (STCout | STCref) && !(ismemset & 2))
{
// If this is an initialization of a reference,
// do nothing
Expand Down Expand Up @@ -12041,7 +12049,7 @@ public:
// Check for block assignment. If it is of type void[], void[][], etc,
// '= null' is the only allowable block assignment (Bug 7493)
// memset
ismemset = 1; // make it easy for back end to tell what this is
ismemset |= 1; // make it easy for back end to tell what this is
e2x = e2x.implicitCastTo(sc, t1.nextOf());
if (op != TOKblit && e2x.isLvalue() && e1.checkPostblit(sc, t1.nextOf()))
{
Expand Down Expand Up @@ -12135,7 +12143,7 @@ public:
if ((t2.ty == Tarray || t2.ty == Tsarray) && isArrayOpValid(e2))
{
// Look for valid array operations
if (!ismemset && e1.op == TOKslice && (isUnaArrayOp(e2.op) || isBinArrayOp(e2.op)))
if (!(ismemset & 1) && e1.op == TOKslice && (isUnaArrayOp(e2.op) || isBinArrayOp(e2.op)))
{
type = e1.type;
if (op == TOKconstruct) // Bugzilla 10282: tweak mutability of e1 element
Expand All @@ -12144,7 +12152,7 @@ public:
}
// Drop invalid array operations in e2
// d = a[] + b[], d = (a[] + b[])[0..2], etc
if (checkNonAssignmentArrayOp(e2, !ismemset && op == TOKassign))
if (checkNonAssignmentArrayOp(e2, !(ismemset & 1) && op == TOKassign))
return new ErrorExp();
// Remains valid array assignments
// d = d[], d = [1,2,3], etc
Expand Down
4 changes: 3 additions & 1 deletion src/expression.h
Expand Up @@ -1159,7 +1159,9 @@ class PreExp : public UnaExp
class AssignExp : public BinExp
{
public:
int ismemset; // !=0 if setting the contents of an array
// &1 != 0 if setting the contents of an array
// &2 != 0 if setting the content of ref variable
int ismemset;

AssignExp(Loc loc, Expression *e1, Expression *e2);
Expression *semantic(Scope *sc);
Expand Down
21 changes: 21 additions & 0 deletions test/runnable/sctor.d
Expand Up @@ -316,6 +316,26 @@ class D14351c : B14351
this(inout int[] arr) inout { super(arr); }
}

/***************************************************/
// 14944

static int[2] tbl14944;

static this()
{
foreach (ref v; tbl14944)
{
// This is an initialization of referenced memory
// rather than the initialization of the reference.
v = 1;
}
}

void test14944()
{
assert(tbl14944[0] == 1);
}

/***************************************************/

int main()
Expand All @@ -324,6 +344,7 @@ int main()
test9665();
test11246();
test13515();
test14944();

printf("Success\n");
return 0;
Expand Down

0 comments on commit 66c6a93

Please sign in to comment.