[PATCH] D50233: [InstCombine] Transform str(n)cmp to memcmp

Adam Reichold via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 4 13:13:14 PDT 2018


adamreichold added a comment.

In https://reviews.llvm.org/D50233#1223705, @efriedma wrote:

> > But that also implies that you have to emit an inline implementation since you might not control what the implementation of memcmp supplied by libc does?
>
> Assuming there isn't a data race, the libc implementation of memcmp can't actually do anything undefined.  In assembly, "uninitialized" data always has some fixed value.


Sorry for going off into the land of imagined libc implementations here, but for example it could update a thread local variable whenever it reads a byte and my program could then read this variable and hence observe the value of the uninitialized memory. I know this a useless and contrived way to implement `memcmp`, I just think this shows that if one calls an external function that is not guaranteed to be free of side-effects, those side-effects could be reflected into the current translation unit. And while even this would probably not be a problem, since the compiler will by construction not know that I processing undefined values when I access that thread local variable and hence will not call out UB on me, this could even become a correctness issue if I make assumptions about this variable's value when the `strcmp` succeeds.


Repository:
  rL LLVM

https://reviews.llvm.org/D50233





More information about the llvm-commits mailing list