libc malloc vs. llvm::MallocInst


have a short look at the following simple c-prog:

#include <stdlib.h>

int main(int argc, char* argv) {

void* buf = malloc(10 * sizeof(char*));

/* do sth with buf, so that it is not “optimized away” */

return 0;


When you compile this using a plain llvm-gcc, the call to libc-malloc is left inside.But compiling it with -O2 alters the call to llvm::MallocInst.

Now i would like to know, why this is done.
Is the libc-malloc still used?

There is also a pass, called RaiseAllocation (well … at least i think so) and i remember in previous versions (2.2)
of llvm i read a commentary inside the sourcecode that the pass should be used with care because
llvm::MallocInst is not platform-independent. This commentary is removed in the current version. - Why?

This is nothing serious - i am just curious to know some more details :slight_smile:

Thank you in advance.

This is just an internal implementation detail. the LLVM malloc instruction still calls libc malloc. Using an instruction like this gives us slightly more type information, that's all.