tech-toolchain archive

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

Re: -current gcc optimizations and XEmacs

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.

Building the standard library _is_ a special case, so library developers
need to be aware of this and annotate their code appropriately so that
the knowledge about the standards behaviour is not assumed.  Building
this code with either -fno-builtin-memset or -fno-builtin-malloc is

IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.

Home | Main Index | Thread Index | Old Index