From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 7110 invoked by alias); 3 May 2003 23:26:03 -0000 Mailing-List: contact gcc-prs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-prs-owner@gcc.gnu.org Received: (qmail 7051 invoked by uid 71); 3 May 2003 23:26:00 -0000 Date: Sat, 03 May 2003 23:26:00 -0000 Message-ID: <20030503232600.7050.qmail@sources.redhat.com> To: nobody@gcc.gnu.org Cc: gcc-prs@gcc.gnu.org, From: Dan Nicolaescu Subject: Re: c/2462: "restrict" implementation bug Reply-To: Dan Nicolaescu X-SW-Source: 2003-05/txt/msg00214.txt.bz2 List-Id: The following reply was made to PR c/2462; it has been noted by GNATS. From: Dan Nicolaescu 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 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; }