Issue 58071
Summary Missed optimization inlining malloc
Labels
Assignees
Reporter levodelellis
    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);
}

```
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to