------- Comment #2 from rguenth at gcc dot gnu dot org 2010-03-28 16:33 -------
Confirmed. The problem seems to be gimplification of type sizes where
we end up putting the size calculation stmts into the conditional block,
a place not dominating the 2nd stmt where we re-use it:
x2d = (double[0:(unsigned int) (SAVE_EXPR <(<unnamed-signed:32>) nx +
-1>)][0:(unsigned int) SAVE_EXPR <D.2820>] *) x1d;
if (choice != 0) goto <D.2817>; else goto <D.2818>;
<D.2817>:
ny.2 = ny;
D.2820 = ny.2 + -1;
D.2821 = (unsigned int) D.2820;
D.2822 = D.2821 + 1;
D.2823 = &(*x2d)[1]{lb: 0 sz: D.2822 * 8}[0];
D.2824 = (int) D.2823;
x1d.3 = (int) x1d;
D.2826 = D.2824 - x1d.3;
D.2827 = D.2826 /[ex] 8;
delta = (long unsigned int) D.2827;
goto <D.2828>;
<D.2818>:
D.2829 = (unsigned int) D.2820;
D.2830 = D.2829 + 1;
D.2831 = &(*x2d)[1]{lb: 0 sz: D.2830 * 8}[0];
D.2832 = (int) D.2831;
x1d.4 = (int) x1d;
D.2834 = D.2832 - x1d.4;
D.2835 = D.2834 /[ex] 8;
delta = (long unsigned int) D.2835;
<D.2828>:
printf (&"Choice: %d, Delta: %ld\n"[0], choice, delta);
also see how the type-sizes in the cast are not gimplified. Thus, if
we'd have gimplified type-sizes when gimplifying
<<cleanup_point <<< Unknown tree: expr_stmt
(void) (x2d = (double[0:(unsigned int) (SAVE_EXPR <(<unnamed-signed:32>) nx +
-1>)][0:(unsigned int) (SAVE_EXPR <(<unnamed-signed:32>) ny + -1>)] *) x1d) >>>
>>;
it all would have worked out. The C frontend seems to be lucky because
it decomposes the address difference internally:
if (choice != 0)
{
delta = (long unsigned int) (((int) ((double *) x2d + (unsigned int)
SAVE_EXPR <ny> * 8) - (int) x1d) /[ex] 8);
}
else
{
delta = (long unsigned int) (((int) ((double *) x2d + (unsigned int)
SAVE_EXPR <ny> * 8) - (int) x1d) /[ex] 8);
}
but even changing the testcase to sth different shows that for C we
properly gimplify type-sizes of casts.
--
rguenth at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Ever Confirmed|0 |1
Keywords| |wrong-code
Known to fail| |4.3.4 4.4.2 4.5.0
Last reconfirmed|0000-00-00 00:00:00 |2010-03-28 16:33:10
date| |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43555