public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/36013]  New: Wrong code involving restricted pointers to non-restricted pointers
@ 2008-04-22 15:54 rainy6144 at gmail dot com
  2008-04-22 22:18 ` [Bug middle-end/36013] [4.1/4.3 Regression] " rguenth at gcc dot gnu dot org
                   ` (11 more replies)
  0 siblings, 12 replies; 13+ messages in thread
From: rainy6144 at gmail dot com @ 2008-04-22 15:54 UTC (permalink / raw)
  To: gcc-bugs

The program below aborts at runtime when compiled by gcc 4.3.0 with option "-O2
-std=c99" (it runs correctly without optimization or when compiled with "icc
-std=c99 -restrict").  I believe it should have defined behavior according to
the standard (see e.g. PR14192), for p[0] and q[0] are not restricted pointers,
and p[0][0] is based on p[0] but not p.  Intuitively, p and q should behave
like two different arrays of pointers, and we may well want to store aliasing
pointers into them.

This is apparently due to the simplistic find_base_decl() in 4.3.0, which is
quite different the standard's definition of "based on".  If I understand
correctly, for two pointers p and q, only when p is provably based on some
restricted pointer p0 (along all control paths), and q is provably not based on
it, can we be sure that a modification to *q can never change *p.

>From a casual glance of the 4.3.0 source, it seems that "restrict" is not well
supported by the tree passes, but the alias sets in the generated RTL make some
use of it.  Proper support, either at RTL or tree level, may mean a lot of
work, but in the meantime we had better agree on the meaning of the standard
and avoid generating wrong code :)

==============================================
#include <stdlib.h>

/* fail by gcc-4.3.0 */
void f(int **restrict p, int **restrict q)
{
  p[0][0] = 1;
  q[0][0] = 2;
  if (p[0][0] != 2) abort();
}

int main(void)
{
  int a;
  int *p1 = &a, *p2 = &a;
  f(&p1, &p2);
  return 0;
}


-- 
           Summary: Wrong code involving restricted pointers to non-
                    restricted pointers
           Product: gcc
           Version: 4.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: rainy6144 at gmail dot com
 GCC build triplet: i686-pc-linux-gnu
  GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu


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


^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2008-05-07  8:22 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-04-22 15:54 [Bug middle-end/36013] New: Wrong code involving restricted pointers to non-restricted pointers rainy6144 at gmail dot com
2008-04-22 22:18 ` [Bug middle-end/36013] [4.1/4.3 Regression] " rguenth at gcc dot gnu dot org
2008-04-25  9:21 ` [Bug middle-end/36013] [4.1/4.3/4.4 " jakub at gcc dot gnu dot org
2008-04-25 10:07 ` jakub at gcc dot gnu dot org
2008-04-25 11:37 ` jakub at gcc dot gnu dot org
2008-04-28  4:39 ` mmitchel at gcc dot gnu dot org
2008-05-06 14:23 ` ian at airs dot com
2008-05-06 22:56 ` jakub at gcc dot gnu dot org
2008-05-07  4:39 ` ian at airs dot com
2008-05-07  7:46 ` jakub at gcc dot gnu dot org
2008-05-07  8:02 ` jakub at gcc dot gnu dot org
2008-05-07  8:08 ` jakub at gcc dot gnu dot org
2008-05-07  8:22 ` rguenther at suse dot de

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