<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/58071>58071</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Missed optimization inlining malloc
</td>
</tr>
<tr>
<th>Labels</th>
<td>
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
levodelellis
</td>
</tr>
</table>
<pre>
Below but you can see it in the explorer if you comment out line 11 and uncomment 12 https://godbolt.org/z/YGbTsTf1G
if you compile the below with `clang -O3 -mllvm -attributor-enable=module` you'll get no mallocs/free. Calling an indirect function like mymalloc will inline but no longer optimize out malloc/free
```
#include <stdio.h>
#include <stdlib.h>
int getValue() { return 1; }
//void*mymalloc(int i) { return malloc(i); }
void*mymalloc(int i) __THROW __attribute_malloc__
__attribute_alloc_size__ ((1)) __wur { return malloc(i); }
int main(int argc, char *argv[]) {
char*buf=malloc(16);
//char*buf=mymalloc(16);
buf[0] = getValue() + '0';
buf[1] = 0;
puts(buf);
free(buf);
}
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyNVE2P2jAQ_TXOZQRyYhLCIQdY2u2lWqlateoJOXgS3Do2Smy27K_vJCECdrVVUT4Yvfl4b8aT0qlzsUHjXqAMHs4uwF5a6BBBe9AW_AEB_xyNa7EFXY0ermnQenAUYbRFiGOQVkGwExIncPD-2DGxZslnumqnSmf83LU1Wa90_3wsn7vnKn5kfMv4enxeCxy1waF4OZB70f4ALON7I20NsycBs8aYUwMz6X2ribtrZ2hlaZCJbeNUoD8Z77OxZGkM1OjBOmikMW7fUf2qRZzDA9maMpJmbZVuce-hIh1eO0vafiM05zGGKFAabQfBfa8om3G2pra4o9eNfsWhIaP3pcCtNqJzuUYzEdruTVAITDx0Xmk3PzDx6QPU6PIWHrtFnSZd36UJyJKcJStgyw206ENrIWZiQ_b2jsMwjJPTiiXrSRmF9pn0m_grSMBdrn_E73bPX749_aD3NBfcjV673RgM_e8WHtGO-rfbwSAjj_uKQ7aX0P4fp2tHGqnthZJsa3J-gP1BUppkTfaJpRuWbi9ar5R6F_IoQ9Wfn6lMnI11phqrsYH3zueP3XuPdMOpII1x-25YCQlIlpzu90HxFMRvsWPwdHjz3uW-0nDa3gNvxj8dwQiLOMsWi1We52mkCqFWYiUjr73B4qvuOlTTqZbDKgznvl-UUWsUWlO82XDa0FDOaXXJ6Ffz8podW_eL1opMyhuw370058s4OhQllrLKME9kKmMep7gSSbbkGReLisdKRUbS-nfFOLNIFwlPEr4SnPNFztO5yJaLrEyXpRBpulCcLTjS-M28L9x_a6K2GDiUoe4INLrz3RWUXadrizjll8EfHEXgySk0SF-GLho4FwPhvw8TkNc">