diff options
author | Eli Friedman <efriedma@codeaurora.org> | 2019-01-09 23:39:26 +0000 |
---|---|---|
committer | Eli Friedman <efriedma@codeaurora.org> | 2019-01-09 23:39:26 +0000 |
commit | d4e7a0d83ca785925a4f8c82d114377f5b156bbf (patch) | |
tree | 1c40cbaf08d91cd6ef285178ef823409bb25a056 /llvm/lib | |
parent | 30ba0a0c950a0cdf23a70fce6c16d501c5f238c8 (diff) | |
download | bcm5719-llvm-d4e7a0d83ca785925a4f8c82d114377f5b156bbf.tar.gz bcm5719-llvm-d4e7a0d83ca785925a4f8c82d114377f5b156bbf.zip |
[SimplifyLibCalls] Fix memchr expansion for constant strings.
The C standard says "The memchr function locates the first
occurrence of c (converted to an unsigned char)[...]". The expansion
was missing the conversion to unsigned char.
Fixes https://bugs.llvm.org/show_bug.cgi?id=39041 .
Differential Revision: https://reviews.llvm.org/D55947
llvm-svn: 350775
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp b/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp index a50575b0256..1bb26caa2af 100644 --- a/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp +++ b/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp @@ -798,8 +798,11 @@ Value *LibCallSimplifier::optimizeMemChr(CallInst *CI, IRBuilder<> &B) { Bitfield.setBit((unsigned char)C); Value *BitfieldC = B.getInt(Bitfield); - // First check that the bit field access is within bounds. + // Adjust width of "C" to the bitfield width, then mask off the high bits. Value *C = B.CreateZExtOrTrunc(CI->getArgOperand(1), BitfieldC->getType()); + C = B.CreateAnd(C, B.getIntN(Width, 0xFF)); + + // First check that the bit field access is within bounds. Value *Bounds = B.CreateICmp(ICmpInst::ICMP_ULT, C, B.getIntN(Width, Width), "memchr.bounds"); |