<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/155636>155636</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Attribute alloc_size is limited to two parameters only
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
earnol
</td>
</tr>
</table>
<pre>
Attribute alloc_size aimed to help compiler to determine size parameters is limited to only two use cases:
```
void* calloc( size_t num, size_t size ) __attribute__((alloc_size(1, 2)));
void* malloc( size_t size ) __attribute__((alloc_size(1)));
```
Where the final allocation size is either _size_ or _size * num_ which leaves some custom allocation function like:
`void* allocateNetworkPacket(size_t payloadSize, size_t sizeLimit, size_t headerSize, uint32_t allocationID);`
unsuitable to use this mechanism as in this particular case the allocation size is _headerSize + payloadSize_ but using the declaration like
`void* allocateNetworkPacket(size_t payloadSize, size_t sizeLimit, size_t headerSize, uint32_t allocationID) __attribute__((alloc_size(1, 3)));`
yields invalid diagnostics.
I propose to expand alloc_size attribute functionality to make it more useful for cases like above.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJysVEuL40YQ_jWtS7FGalka-aCDJ4thIYRADjmKkrpsVaYfoh-eOL8-qG3P2GEPCVlocLtUj6--qv4wBD5Zol40r6L5WmCKs_M9obdOF6NTl34fo-cxRQLU2k1D4L8IkA0piA5m0gtMziysya8GRZG8YUuQHRf0aFZTAA6g2XC8BjqrLxDfHaRAMGGgIOq9KPeiLW-n3J8dKyH3MOXKQnY55xDBJiPkT_d_uZCQOxgGvIMdBiE7IbtPzEJ21RokhdzdTv36UMT8s8h_SfuU8bEFUe5_n8kTxJngyBb1lUaM7Oy1BAcgjjN5yAkHcLcbrLBsMgO8zzzNoAnPFCA4QzClEJ15zHVMdsoXzW_0weW9u5sj_ULx3fm3X3F6oyhkd-t1wYt2qH7LDT0R-_M6sgfbTKjI3x0BEttYyyE-QPn29UZFZiDZkDjiqGkd-zrtOHMAQ9OMloMBDMD2alzQR56SRp9XAjJr3-Fr-EQBQr4-wh9gTBFSYHvK0YomjR4_mIH_w8uPIObfbWn9tFOZyAuTVitXZ9SsQDGerAuRp7C5Lto3WLxbXMhE058LWvX0Zj8e8n1VUHO8rM4G3wg4gnGe1hEdk4ajuw4hXGnD0Z1pU6i-Vrt6hwX11UvT1uXLrmmLuS9lPTXjWLV113at3Kqxruuqoqau6l3dqYJ7Wcqm7ORL1VS7qt1st9XYqOPYvVRyxFKKbUkGWW-0PpuN86eCQ0jUV03T1m2hcSQdsk5Jaekd8lch5Spbvl-DvozpFMS21Bxi-EwTOWr6vow9S9KqRg96tSpUkbzu5xiXrE7yIOThxHFO42ZyRsjDWuT282Xx7g-aopCHDC0IebhhP_fy7wAAAP__LOvRzw">