[PATCH] D103009: [DSE] Transform memset + malloc --> calloc (PR25892)
Evgenii Stepanov via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 15 10:59:10 PDT 2021
eugenis added a comment.
In D103009#2879416 <https://reviews.llvm.org/D103009#2879416>, @yurai007 wrote:
> Hello @kcc @eugenis @pgousseau, sorry for bothering you. I added you to this review because transformation introduced in this change breaks msan_test (memcpy_unaligned/TestUnalignedMemcpy unit test).
> I'm quite convinced that after my change Clang does what GCC would do if compliled msan_test.cpp file with -Ofast: https://godbolt.org/z/f7s81hjaM
> Therefore I'm pretty sure that transformation works correctly (as on GCC) but it simply doesn't play well with MSan.
> Since I'm not MSan expert it would be great if you could take a look on this and confirm whether or not my understanding of issue is correct.
Right, so this change replaces malloc with calloc in
if (src_is_poisoned)
src_origin = __msan_get_origin(src);
else
memset(src, 0, sz);
because the other branch contains UB.
The test can be fixed by adding `__msan_allocated_memory(ptr, size)` before the call to `__msan_get_origin`, but I'd rather disable this optimization in functions with `sanitize_memory` attribute because it could make us miss bugs.
If possible, it's OK to disable only the CFG-aware part of the opt. I.e. malloc + memset in linear code (or even same BB) is fair game.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D103009/new/
https://reviews.llvm.org/D103009
More information about the llvm-commits
mailing list