tech-toolchain archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: -current gcc optimizations and XEmacs



On Mon, Oct 31, 2016 at 02:08:46PM +0000, Richard Earnshaw wrote:
> On 28/10/16 20:00, Joerg Sonnenberger wrote:
> > On Fri, Oct 28, 2016 at 01:22:10PM +0000, Christos Zoulas wrote:
> >> Delete the function. gcc detects
> >>
> >>     ptr = malloc(nmemb * size);
> >>     memset(ptr, 0, nmemb * size);
> >>
> >> and changes it into:
> >>
> >>     calloc(nmemb, size);
> >>
> >> so the function ends up being:
> >>
> >>     __ptr_t
> >>     calloc (__malloc_size_t nmemb, __malloc_size_t size)
> >>     {
> >>          return calloc(nmemb, size);
> >>     }
> >>
> >> and that does not work very will as you noticed :-)
> >
> > It's clearly a GCC bug to do this. Deleting calloc doesn't help as it
> > will just result in inconsistent definitions of malloc/realloc vs calloc
> > to be used.
> >
> No, it's a perfectly safe optimization at other times when dealing with
> functions defined by the standard.  Compilers are permitted to know what
> the standard library functions do and optimize accordingly.

Please read again. GCC is changing the implementation of calloc from
malloc+memset to calloc. That is completely brain dead. It has nothing
to do with the semantics of calloc. The "as-if" rule is clearly violated
when you introduce recursion. There is no excuse for this behavior. It
is no different from turning a "while (*p) *p++= 0;" loop into a memset
when inside a function called memset.

Joerg


Home | Main Index | Thread Index | Old Index