[PATCH] D108485: [DSE] Check post-dominance for malloc+memset->calloc transform.

Dávid Bolvanský via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 20 14:22:06 PDT 2021


xbolva00 added a comment.

Also some notes from https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83022

implementing a check to see if the only condition between the malloc and memset is 'ptr != 0'.

+1. This is probably what we really want to make everybody happy.



================
Comment at: llvm/test/Transforms/DeadStoreElimination/noop-stores.ll:415
 ; CHECK-NEXT:    [[CMP:%.*]] = icmp eq i8* [[CALL]], null
 ; CHECK-NEXT:    br i1 [[CMP]], label [[CLEANUP:%.*]], label [[IF_END:%.*]]
 ; CHECK:       if.end:
----------------
I would rather see better fix, so this motivating case still works (allow 'ptr compared with NULL'). Othewise I see no value from this optimization at all and it should be just removed from DSE.

I am somewhat scared that people talking about this pattern
```
memset(malloc(size), 0, size)
```

not suprised that why there are so many nasty bugs/exploits in C codebases.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D108485/new/

https://reviews.llvm.org/D108485



More information about the llvm-commits mailing list