Skip to content

Commit

Permalink
Merge pull request #3848 from WalterBright/fix13237
Browse files Browse the repository at this point in the history
fix Issue 13237 Wrong code with -inline -O
  • Loading branch information
9rnsr committed Aug 6, 2014
2 parents d0d95cd + 02ca8d7 commit 0131c14
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 7 deletions.
43 changes: 36 additions & 7 deletions src/backend/gother.c
Expand Up @@ -921,9 +921,9 @@ void copyprop()
/* and the d=b copy elem now reaches the end */
/* of the block (the d=a elem didn't). */
}
if (recalc)
goto Lagain;
}
if (recalc)
goto Lagain;
}

/*****************************
Expand All @@ -940,6 +940,8 @@ STATIC void cpwalk(register elem *n,vec_t IN)

assert(n && IN);
/*chkvecdim(exptop,0);*/
if (recalc)
return;
op = n->Eoper;
if (op == OPcolon || op == OPcolon2)
{
Expand Down Expand Up @@ -1086,17 +1088,44 @@ STATIC void cpwalk(register elem *n,vec_t IN)
}
if (foundelem) /* if we can do the copy prop */
{
cmes3("Copyprop, from '%s' to '%s'\n",
(v->Sident) ? (char *)v->Sident : "temp",
(f->Sident) ? (char *)f->Sident : "temp");

#ifdef DEBUG
if (debugc)
{
printf("Copyprop, from '%s'(%d) to '%s'(%d)\n",
(v->Sident) ? (char *)v->Sident : "temp", v->Ssymnum,
(f->Sident) ? (char *)f->Sident : "temp", f->Ssymnum);
}
#endif
type *nt = n->ET;
el_copy(n,foundelem->E2);
n->Ety = ty; // retain original type
n->ET = nt;

/* original => rewrite
* v = f
* g = v => g = f
* f = x
* d = g => d = f !!error
* Therefore, if g appears as an rvalue in expnod[], then recalc
*/
for (size_t i = 1; i < exptop; ++i)
{
if (expnod[i]->E2 == n)
{
symbol *g = expnod[i]->E1->EV.sp.Vsym;
for (size_t j = 1; j < exptop; ++j)
{
if (expnod[j]->E2->EV.sp.Vsym == g)
{
++recalc;
break;
}
}
break;
}
}

changes++;
recalc++;
}
//else dbg_printf("not found\n");
noprop:
Expand Down
17 changes: 17 additions & 0 deletions test/runnable/test23.d
Expand Up @@ -1462,6 +1462,22 @@ void test71()

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

size_t getLength(int[] arr) { return arr.length; }

void test13237()
{
int[] arr = [0];
immutable size_t len = getLength(arr);

arr.length--;

assert(len == 1); // ok
if (len) { auto l = len; }
assert(len == 1); // len cannot be changed, but produces Assertion failure with "-O -inline"
}

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

void main()
{
test1();
Expand Down Expand Up @@ -1528,6 +1544,7 @@ void main()
test69();
test70();
test71();
test13237();

printf("Success\n");
}

0 comments on commit 0131c14

Please sign in to comment.