This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
Re: Can realloc be marked as a mallloc-like function?
- From: "H.J. Lu" <hjl at lucon dot org>
- To: Richard Guenther <richard dot guenther at gmail dot com>
- Cc: gcc at gcc dot gnu dot org, fortran at gcc dot gnu dot org, jb at gcc dot gnu dot org, GNU C Library <libc-alpha at sources dot redhat dot com>
- Date: Sun, 15 Jul 2007 15:31:30 -0700
- Subject: Re: Can realloc be marked as a mallloc-like function?
- References: <20070714160016.GA7949@lucon.org> <84fc9c000707151252g285e45bbpcf52992c88d45428@mail.gmail.com>
On Sun, Jul 15, 2007 at 09:52:02PM +0200, Richard Guenther wrote:
> On 7/14/07, H.J. Lu <hjl@lucon.org> wrote:
> >This patch
> >
> >http://gcc.gnu.org/ml/gcc-patches/2007-07/msg00165.html
> >
> >causes the regression:
> >
> >http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32748
> >
> >The only relevant change is
> >
> >Index: gcc/fortran/trans-decl.c
> >===================================================================
> >--- gcc/fortran/trans-decl.c (revision 126214)
> >+++ gcc/fortran/trans-decl.c (working copy)
> >@@ -2276,6 +2276,7 @@ gfc_build_builtin_function_decls (void)
> > (PREFIX("internal_realloc")),
> > pvoid_type_node, 2, pvoid_type_node,
> > gfc_index_int_type_node);
> >+ DECL_IS_MALLOC (gfor_fndecl_internal_realloc) = 1;
> >
> > gfor_fndecl_allocate =
> > gfc_build_library_function_decl (get_identifier (PREFIX("allocate")),
> >
> >In calls.c, there are comments:
> >
> > /* The return value from a malloc-like function can not alias
> > anything else. */
> >
> >It looks like gcc assumes a functon marked with DECL_IS_MALLOC won't
> >return an address which can alias something else. But it isn't true
> >for realloc. Now, the qestions are
> >
> >1. Can gcc make such an assumption?
>
> No, it can't. The returned memory may alias the original memory.
>
> >2. Can realloc be marked as DECL_IS_MALLOC.
>
> ... with DECL_IS_MALLOC the following
>
> int *p;
> p = malloc (4);
> *p = 0;
> p = realloc (p, 4);
> *p = 1;
>
> will have VOPs that do not prevent re-ordering of the two stores.
>
> >BTW, glibc also marks realloc with __attribute_malloc__.
>
> Which is wrong as well.
I opened 2 bugs:
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32771
http://sourceware.org/bugzilla/show_bug.cgi?id=4792
H.J.