Skip to content
This repository has been archived by the owner on Jun 20, 2019. It is now read-only.

Commit

Permalink
Merge pull request #640 from ibuclaw/brokenregex
Browse files Browse the repository at this point in the history
Fix Bug 286: Returning AA value whose key is a RefCounted type gets wrong value.
  • Loading branch information
ibuclaw committed Mar 18, 2018
2 parents 31c6fcd + 6d67b5e commit faab4ac
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 11 deletions.
5 changes: 5 additions & 0 deletions gcc/d/ChangeLog
@@ -1,3 +1,8 @@
2018-03-18 Iain Buclaw <ibuclaw@gdcproject.org>

* d-codegen.cc (stabilize_expr): Move modify expression rewrite...
* expr.cc (ExprVisitor::binop_assignment): ... here.

2018-03-11 Iain Buclaw <ibuclaw@gdcproject.org>

* expr.cc (ExprVisitor::visit(StringExp)): Include null terminator
Expand Down
9 changes: 0 additions & 9 deletions gcc/d/d-codegen.cc
Expand Up @@ -541,15 +541,6 @@ stabilize_expr (tree *valuep)
*valuep = rhs;
return lhs;

case MODIFY_EXPR:
case INIT_EXPR:
/* Given e1 = e2:
Store the leftmost 'e1' expression in VALUEP. */
lhs = TREE_OPERAND (expr, 0);
stabilize_expr (&lhs);
*valuep = lhs;
return expr;

default:
return NULL_TREE;
}
Expand Down
12 changes: 10 additions & 2 deletions gcc/d/expr.cc
Expand Up @@ -171,10 +171,18 @@ class ExprVisitor : public Visitor
e1b = ce->e1;
}

/* The LHS expression could be an assignment, to which it's operation gets
lost during gimplification. Stabilize lhs for assignment. */
/* Stabilize LHS for assignment. */
tree lhs = build_expr (e1b);
tree lexpr = stabilize_expr (&lhs);

/* The LHS expression could be an assignment, to which it's operation gets
lost during gimplification. */
if (TREE_CODE (lhs) == MODIFY_EXPR)
{
lexpr = compound_expr (lexpr, lhs);
lhs = TREE_OPERAND (lhs, 0);
}

lhs = stabilize_reference (lhs);

/* Save RHS, to ensure that the expression is evaluated before LHS. */
Expand Down
39 changes: 39 additions & 0 deletions gcc/testsuite/gdc.dg/runnable.d
Expand Up @@ -1547,6 +1547,44 @@ void test285()

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

// Bug 286

void test286()
{
struct K286
{
int count;
this(this)
{
count++;
}
}

struct S286
{
int data;
this(K286 key)
{
data = key.count;
}
}

S286 getData(K286 key)
{
static S286[K286] getCache;
auto p = key in getCache;
if (p)
return *p;
return (getCache[key] = S286(key));
}

auto s = getData(K286());
if (s.data == 0)
assert(0);
}

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

void main()
{
test2();
Expand Down Expand Up @@ -1581,6 +1619,7 @@ void main()
test250();
test273();
test285();
test286();

printf("Success!\n");
}

0 comments on commit faab4ac

Please sign in to comment.