http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56955
Bug #: 56955
Summary: documentation for attribute malloc contradicts itself
Classification: Unclassified
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: other
AssignedTo: [email protected]
ReportedBy: [email protected]
The GCC manual's definition of the malloc function attribute is:
"The malloc attribute is used to tell the compiler that a function may be
treated as if any non-NULL pointer it returns cannot alias any other pointer
valid when the function returns and that the memory has undefined content. This
often improves optimization. Standard functions with this property include
malloc and calloc. realloc-like functions do not have this property as the
memory pointed to does not have undefined content."
It says that the attribute implies that allocated memory has undefined content,
but then it says that calloc has this property, despite the fact that memory
allocated by calloc has well-defined content.
Since calloc is already marked with this attribute in lots of places (including
GLIBC), and since the undefined-content part of this attribute seems less
important than the aliasing part for optimizers anyway, I suggest just removing
the undefined-content language from the description of the attribute.
Also, the last sentence says that realloc-like functions don't qualify since
their memory does not have undefined content. The comment on GLIBC's
declaration of realloc says that realloc doesn't qualify since the returned
pointer may alias the argument pointer (for some definition of alias). GLIBC's
comment seems more likely to be the real reason, and it doesn't rely on the
undefined-content language.