[clang] [Clang] Allow malloc and alloc_size attributes for functions returning structs (PR #165433)

Marco Elver via cfe-commits cfe-commits at lists.llvm.org
Mon Nov 3 07:30:49 PST 2025


melver wrote:

This LGTM, but I'd like to hear from others more familiar with the history of these attributes.

In particular, we'd be diverging from GCC's behaviour, so that users would now need to do:
```
#ifdef __clang__
#define __attribute_malloc_span  __attribute__((malloc))
#define __attribute_malloc_size_span(...)  __attribute__((alloc_size(__VA_ARGS__)))
#else
#define __attribute_malloc_span  
#define __attribute_malloc_size_span(...) 
#endif 
```

IMHO, that's reasonable. Maybe we can ask GCC folks to also permit these attributes on functions that return span-like objects.

https://github.com/llvm/llvm-project/pull/165433


More information about the cfe-commits mailing list