[llvm-dev] Bug 50482 - optimizer malloc

bhumitram kumar via llvm-dev llvm-dev at lists.llvm.org
Tue Nov 16 10:33:04 PST 2021


Hi,
    This is my first post and I am looking at the bug 50482 . It is related
to malloc optimization. I have a doubt related to malloc optimization.
Here is the code:-

#include <stdlib.h>
int test() {
  char *x = malloc(-1);
  char *y = malloc(2);
  int ret = (x != NULL) && (y != NULL);
  free(x); free(y);
  return ret;
}

Above program returns 1.

During optimization (-O1) when llvm IR goes through instruction
combining pass then program behaves incorrect.

This link follows Instruction combining pass.

https://github.com/llvm/llvm-project/blob/main/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp#L2639

Where it is mentioned that

If we have a malloc call which is only used in any amount of
comparisons to null and free calls, delete the calls and replace the
comparisons with true or false as appropriate.

but is it feasible solution to replace every malloc call with true or
false when comparison to null and free calls?

Thank you,

Bhumitram Kumar
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20211116/6cd4fe09/attachment.html>


More information about the llvm-dev mailing list