https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67618

            Bug ID: 67618
           Summary: malloc+memset optimization breaks code
           Product: gcc
           Version: 5.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: daniel.gutson at tallertechnologies dot com
  Target Milestone: ---

compiling the following code with -O2

#include <stdlib.h>
#include <string.h>

char* function(size_t x)
{
    void* ret = malloc(x);
    if (x > 12)
        memset(ret, 0, x);

    return (char*)ret;
}

int main(void)
{
    return 0;
}

causes gcc to wrongly replace function's content by a call to calloc.
This comes from https://gcc.gnu.org/bugzilla/show_bug.cgi?id=57742

Additionally, in the case for RTEMS for example, if the function itself
(caller) is calloc, causes a recursive call. (Maybe this could be addressed in
two separate issues).

Reply via email to