public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "jakub at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug tree-optimization/47538] [4.6 Regression] GNU Scientific Library miscompiled by gcc 4.6
Date: Mon, 31 Jan 2011 10:45:00 -0000	[thread overview]
Message-ID: <bug-47538-4-L94nDH9st4@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-47538-4@http.gcc.gnu.org/bugzilla/>

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47538

--- Comment #10 from Jakub Jelinek <jakub at gcc dot gnu.org> 2011-01-31 10:27:58 UTC ---
Self-contained testcase:

/* PR tree-optimization/47538 */

struct S
{
  double a, b, *c;
  unsigned long d;
};

__attribute__((noinline, noclone)) void
foo (struct S *x, const struct S *y)
{
  const unsigned long n = y->d + 1;
  const double m = 0.25 * (y->b - y->a);
  x->a = y->a;
  x->b = y->b;
  if (n == 1)
    {
      x->c[0] = 0.;
    }
  else if (n == 2)
    {
      x->c[1] = m * y->c[0];
      x->c[0] = 2.0 * x->c[1];
    }
  else
    {
      double o = 0.0, p = 1.0;
      unsigned long i;

      for (i = 1; i <= n - 2; i++)
        {
          x->c[i] = m * (y->c[i - 1] - y->c[i + 1]) / (double) i;
          o += p * x->c[i];
          p = -p;
        }
      x->c[n - 1] = m * y->c[n - 2] / (n - 1.0);
      o += p * x->c[n - 1];
      x->c[0] = 2.0 * o;
    }
}

int
main (void)
{
  struct S x, y;
  double c[4] = { 10, 20, 30, 40 }, d[4], e[4] = { 118, 118, 118, 118 };

  y.a = 10;
  y.b = 6;
  y.c = c;
  x.c = d;
  y.d = 3;
  __builtin_memcpy (d, e, sizeof d);
  foo (&x, &y);
  if (d[0] != 0 || d[1] != 20 || d[2] != 10 || d[3] != -10)
    __builtin_abort ();
  y.d = 2;
  __builtin_memcpy (d, e, sizeof d);
  foo (&x, &y);
  if (d[0] != 60 || d[1] != 20 || d[2] != -10 || d[3] != 118)
    __builtin_abort ();
  y.d = 1;
  __builtin_memcpy (d, e, sizeof d);
  foo (&x, &y);
  if (d[0] != -20 || d[1] != -10 || d[2] != 118 || d[3] != 118)
    __builtin_abort ();
  y.d = 0;
  __builtin_memcpy (d, e, sizeof d);
  foo (&x, &y);
  if (d[0] != 0 || d[1] != 118 || d[2] != 118 || d[3] != 118)
    __builtin_abort ();
  return 0;
}


  parent reply	other threads:[~2011-01-31 10:28 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-01-30  2:03 [Bug c/47538] New: " howarth at nitro dot med.uc.edu
2011-01-30  2:07 ` [Bug c/47538] " howarth at nitro dot med.uc.edu
2011-01-30  2:48 ` howarth at nitro dot med.uc.edu
2011-01-30  3:05 ` howarth at nitro dot med.uc.edu
2011-01-30  3:10 ` howarth at nitro dot med.uc.edu
2011-01-30  9:39 ` howarth at nitro dot med.uc.edu
2011-01-30 18:20 ` [Bug c/47538] [4.6 Regression] " hjl.tools at gmail dot com
2011-01-30 22:03 ` hjl.tools at gmail dot com
2011-01-31 10:16 ` [Bug tree-optimization/47538] " jakub at gcc dot gnu.org
2011-01-31 10:29 ` ebotcazou at gcc dot gnu.org
2011-01-31 10:45 ` jakub at gcc dot gnu.org [this message]
2011-01-31 10:53 ` rguenth at gcc dot gnu.org
2011-01-31 12:50 ` jakub at gcc dot gnu.org
2011-01-31 13:18 ` rguenth at gcc dot gnu.org
2011-01-31 13:24 ` rguenth at gcc dot gnu.org
2011-01-31 13:29 ` rguenth at gcc dot gnu.org
2011-01-31 15:57 ` howarth at nitro dot med.uc.edu
2011-01-31 17:07 ` jakub at gcc dot gnu.org
2011-01-31 17:23 ` jakub at gcc dot gnu.org
2011-02-02 18:31 ` dnovillo at gcc dot gnu.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=bug-47538-4-L94nDH9st4@http.gcc.gnu.org/bugzilla/ \
    --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).