Example cases:
strlen(calloc(...)) -> 0
Details
Diff Detail
- Repository
- rL LLVM
Event Timeline
This looks overly specific. Can you teach GetStringLength about this instead? All of the transformations should already work if GetStringLength returns a length of zero.
include/llvm/Analysis/ValueTracking.h | ||
---|---|---|
277 ↗ | (On Diff #147552) | Or should I leave const here and then const_cast for dyn_cast in isStringFromCalloc? |
include/llvm/Analysis/ValueTracking.h | ||
---|---|---|
277 ↗ | (On Diff #147552) | Leave the const here and make the variables in isStringFromCalloc const too. There should be no need for const_cast, dyn_cast will preserve const input types. |
lib/Analysis/ValueTracking.cpp | ||
3392 ↗ | (On Diff #147552) | APInt::isNullValue() is preferable over getZExtValue()==0 because it also handles integer widths > 64 |
lib/Transforms/Utils/SimplifyLibCalls.cpp | ||
---|---|---|
207 ↗ | (On Diff #147758) | " memcpy + store null byte: ... Nope, cannot do this. It will copy bytes even after \0. Strncat does not do it. I removed incorrect transformations for str(n)cat to str(n)cpy. So patch is done. |
It looks like this patch doesn't handle the case where the memory allocated by calloc() is modified?
Ok, I will remove it from InstCombine - https://reviews.llvm.org/D47218
It could be moved to DSE later with that check.
Well, we cannot teach GetStringLength about it then. So it is useless anyway to move it to DSE?
Make sure you test locally before committing. There's no final '}' here, so this broke bots.
Hopefully fixed with rL332990