public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
From: Dan Nicolaescu <dann@ics.uci.edu>
To: nobody@gcc.gnu.org
Cc: gcc-prs@gcc.gnu.org,
Subject: Re: c/2462: "restrict" implementation bug
Date: Sat, 03 May 2003 23:26:00 -0000	[thread overview]
Message-ID: <20030503232600.7050.qmail@sources.redhat.com> (raw)

The following reply was made to PR c/2462; it has been noted by GNATS.

From: Dan Nicolaescu <dann@ics.uci.edu>
To: bangerth@dealii.org
Cc: gcc-gnats@gcc.gnu.org
Subject: Re: c/2462: "restrict" implementation bug
Date: Sat, 03 May 2003 16:16:52 -0700

 With the tweaks below the code in this PR can be added to the
 GCC testsuite in case somebody wants to do that.
 
 /* { dg-do link } */
 
 #include <stdlib.h>
 
 int *  __restrict__ d;
 int *  __restrict__ g;
 int *  __restrict__ h;
 
 struct two_intp {
   int *first;
   int *second;
 };
 
 extern void link_error(void);
 
 /* a malloced pointer, local restricted vars and a global restricted var */
 int*
 foo (int *a, int *b, int *c, int n)
 {
   int i;
   int *f;
   f = (int*) malloc (n * sizeof (int));
 
 
   {
     int * __restrict__ p = a;
     int * __restrict__ q = b;
     int * __restrict__ r = c;
    
     for (i = 0;i < n; i++)
       {
         p[i] = 1;
         q[i] = 1;
         r[i] = 1;
         f[i] = p[i] + q[i];
 
         if (f[i] != 2)
           link_error ();
 
         d[i] = p[i] + r[i];
 
         if (d[i] != 2)
           link_error ();
 
         f[i] += p[i] + q[i];
 
         if (f[i] != 4)
           link_error ();
       }
 
   }
   return f;
 }
 
 
 /* a malloced pointer and a restricted global var */
 int*
 bar (int *  __restrict__ b,
      int *  __restrict__ c, int n)
 {
   int i;
 
   int * f = (int*) malloc (n * sizeof (int));
  
   for (i = 0;i < n; i++)
     {
       b[i] = 1;
       c[i] = 1;
       
       f[i] = b[i] + c[i];
 
       if (f[i] != 2)
         link_error ();
 
       if ((b[i] != 1) || (c[i] != 1))
           link_error ();
       
       d[i] = b[i] + c[i];
       
       if (d[i] != 2)
         link_error ();
       
       f[i] += b[i] + c[i];
 
       if (f[i] != 4)
         link_error ();
       
     }
   return f;
 }
 
 
 /* 2 malloced pointers */
 struct two_intp
 foobar (int *  __restrict__ b,
         int *  __restrict__ c, int n)
 {
   int i;
 
   struct two_intp retval;
 
   int * f = (int*) malloc (n * sizeof (int));
   int * ff = (int*) malloc (n * sizeof (int));
  
   for (i = 0;i < n; i++)
     {
       b[i] = 1;
       c[i] = 1;
 
       f[i] = b[i] + c[i];
 
       if (f[i] != 2)
         link_error ();
       
       ff[i] = b[i] + c[i];
 
       if (ff[i] != 2)
         link_error ();
 
       f[i] += b[i] + c[i];
 
       if (f[i] != 4)
         link_error ();
 
     }
   retval.first = f;
   retval.second = ff;
   return retval;
 }
 
 /* 2 restricted global vars */
 int*
 baz (int *  __restrict__ b,
      int *  __restrict__ c, int n)
 {
   int i;
   for (i = 0;i < n; i++)
     {
       b[i] = 1;
       c[i] = 1;
       g[i] = b[i] + c[i];
       
       if (g[i] != 2)
         link_error ();
       
       d[i] = b[i] + c[i];
 
       if (d[i] != 2)
         link_error ();
 
       g[i] += b[i] + c[i];
 
       if (g[i] != 4)
         link_error ();
     }
   return g;
 }
 
 int main (void)
 {
 
   int *a,  *b,  *c, *f, n;
   struct two_intp twoints;
   f = foo (a, b, c, n);
   f = bar (b, c, n);
   twoints = foobar (b, c, n);
   f = baz (b, c, n);
   return 0;
 }


             reply	other threads:[~2003-05-03 23:26 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-05-03 23:26 Dan Nicolaescu [this message]
  -- strict thread matches above, loose matches on Subject: below --
2003-03-25  3:16 bangerth
2003-03-25  2:07 Dan Nicolaescu
2003-03-25  1:39 bangerth
2001-04-02 14:36 Dan Nicolaescu

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=20030503232600.7050.qmail@sources.redhat.com \
    --to=dann@ics.uci.edu \
    --cc=gcc-prs@gcc.gnu.org \
    --cc=nobody@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).