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

Commit

Permalink
Fix Bug 286: Returning AA value whose key is a RefCounted type gets w…
Browse files Browse the repository at this point in the history
…rong value.
  • Loading branch information
ibuclaw committed Mar 12, 2018
1 parent 89aead4 commit d26f777
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 11 deletions.
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
41 changes: 41 additions & 0 deletions gcc/testsuite/gdc.dg/runnable.d
Expand Up @@ -1547,6 +1547,46 @@ void test285()

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

// Bug 286

void test286()
{
import std.uni : CodepointSet, unicode;

struct S286
{
uint[4] filter;

this(CodepointSet set)
{
auto asciiSet = set & unicode.ASCII;
foreach (iv; asciiSet.byInterval)
{
foreach (v; iv.a .. iv.b)
{
immutable i = ((v >> 7) ^ v) & 0x7F;
filter[i >> 5] |= 1 << (i & 31);
}
}
}
}

S286 getS286(CodepointSet set)
{
static S286[CodepointSet] matcherCache;
auto p = set in matcherCache;
if (p)
return *p;
return (matcherCache[set] = S286(set));
}

auto t = getS286(unicode.Nd);
if (t.filter == [0,0,0,0])
assert(0);
}

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

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

printf("Success!\n");
}

0 comments on commit d26f777

Please sign in to comment.