https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86488
Bug ID: 86488 Summary: malloc attribute when pointer is returned as part of a struct Product: gcc Version: 9.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: gonzalobg88 at gmail dot com Target Milestone: --- I am trying to implementing P0901r0 [0] in jemalloc. The signature of the new memory allocation function looks like this: typedef struct { void *ptr; size_t usize; } smallocx_return_t; smallocx_return_t je_smallocx(size_t size, int flags); I'd like to set the "malloc" [1] attribute for this function but AFAICT this is not currently possible for this new function because the pointer smallocx_return_t::ptr is part of a struct. [0]: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0901r0.html [1]: From https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html > malloc > This tells the compiler that a function is malloc-like, i.e., that the > pointer P > returned by the function cannot alias any other pointer valid when the > function > returns, and moreover no pointers to valid objects occur in any storage > addressed by P. > > Using this attribute can improve optimization. Functions like malloc and > calloc > have this property because they return a pointer to uninitialized or > zeroed-out > storage. However, functions like realloc do not have this property, as they > can > return a pointer to storage containing pointers.