public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "rguenth at gcc dot gnu dot org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/43555] wrong address calculation of multidimensional variable-length array element
Date: Sun, 28 Mar 2010 16:33:00 -0000	[thread overview]
Message-ID: <20100328163310.24910.qmail@sourceware.org> (raw)
In-Reply-To: <bug-43555-18970@http.gcc.gnu.org/bugzilla/>



------- 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


  parent reply	other threads:[~2010-03-28 16:33 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-03-28 15:35 [Bug c++/43555] New: " skir50 at gmail dot com
2010-03-28 15:50 ` [Bug c++/43555] " sezeroz at gmail dot com
2010-03-28 16:33 ` rguenth at gcc dot gnu dot org [this message]
2010-04-09 21:01 ` [Bug c++/43555] [4.3/4.4/4.5/4.6 Regression] " pinskia at gcc dot gnu dot org
2010-04-10 13:37 ` hjl dot tools at gmail dot com
2010-04-10 13:39 ` hjl dot tools at gmail dot com
2010-04-15 14:05 ` rguenth at gcc dot gnu dot org
2010-05-22 19:00 ` rguenth at gcc dot gnu dot org
2010-05-27 18:32 ` jason at gcc dot gnu dot org
2010-05-27 18:36 ` jason at gcc dot gnu dot org
2010-05-27 18:40 ` jason at gcc dot gnu dot org
2010-05-27 19:01 ` jason at gcc dot gnu dot org
2010-05-27 19:10 ` jason at gcc dot gnu dot org
2010-05-27 19:55 ` jakub at gcc dot gnu dot org
2010-05-27 20:02 ` jason at gcc dot gnu dot org
2010-05-27 20:04 ` jason at gcc dot gnu dot org
2010-05-27 20:55 ` jakub at gcc dot gnu dot org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20100328163310.24910.qmail@sourceware.org \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).