Files
clang-p2996/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
Sergei Barannikov 7134d2e9ac [SimplifyLibCalls] Fix memchr misoptimization (#106121)
The `ch` argument of memcmp should be truncated to `unsigned char`
before using it in comparisons. This didn't happen on all code paths.
The following program miscompiled at -O1 and higher:

```C++
#include <cstring>
#include <iostream>

char ch = '\x81';

int main() {
    bool found = std::strchr("\x80\x81\x82", ch) != nullptr;
    std::cout << std::boolalpha << found << '\n';
}
```
2024-08-27 00:11:23 +03:00

162 KiB