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

            Bug ID: 83129
           Summary: calloc zero initialization is not taken into account
                    by gcc
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: denis.campredon at gmail dot com
  Target Milestone: ---

It seems that GCC does not know that calloc initialize the memory to zero.

The the following functions could be optimized to the same assemble, but only
f3 is optimized to:
        xor     eax, eax
        ret

--------------
int f1() {
  char * i = __builtin_calloc(1, 1);
  return *i;
}

int f2() {
  struct s{int i;}* a = __builtin_calloc(1, sizeof(*a));

  return a->i;
}

int f3() {
    char * i = (char*)__builtin_calloc(1, 1);
    i[0] = 0;
    return *i;
}
--------------

Reply via email to