I believe LLVM actually does all kinds of promotion that ends up removing
malloc calls. Maybe i'm just misremembering.
Yes, LLVM deletes dead malloc calls and does other things as well. The C
spec defines the behavior of malloc/free, and from this description I
believe that it is safe to do this (e.g. C99 second 7.20.3). Note,
however, that Mark's point above about calling sbrk is beyond the
standard: conformant programs can't know anything about sbrk.
Assuming standards compliant programs, this can still cause changes in
observable behavior. In particular, something like this:
malloc(HEAPSIZE-100); // dead
P = malloc(1000); // not dead
*P = x;