mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-10-19 11:02:59 +02:00
Fixing a corner-case bug in strchr and strrchr lib call optimizations where
the input character is not converted to char before comparing with zero. The patch was discussed in this thread: http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20130812/184069.html llvm-svn: 188489
This commit is contained in:
parent
cacfb5333a
commit
37d3ce60e8
@ -477,7 +477,7 @@ struct StrChrOpt : public LibCallOptimization {
|
|||||||
|
|
||||||
// Compute the offset, make sure to handle the case when we're searching for
|
// Compute the offset, make sure to handle the case when we're searching for
|
||||||
// zero (a weird way to spell strlen).
|
// zero (a weird way to spell strlen).
|
||||||
size_t I = CharC->getSExtValue() == 0 ?
|
size_t I = (255 & CharC->getSExtValue()) == 0 ?
|
||||||
Str.size() : Str.find(CharC->getSExtValue());
|
Str.size() : Str.find(CharC->getSExtValue());
|
||||||
if (I == StringRef::npos) // Didn't find the char. strchr returns null.
|
if (I == StringRef::npos) // Didn't find the char. strchr returns null.
|
||||||
return Constant::getNullValue(CI->getType());
|
return Constant::getNullValue(CI->getType());
|
||||||
@ -513,7 +513,7 @@ struct StrRChrOpt : public LibCallOptimization {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Compute the offset.
|
// Compute the offset.
|
||||||
size_t I = CharC->getSExtValue() == 0 ?
|
size_t I = (255 & CharC->getSExtValue()) == 0 ?
|
||||||
Str.size() : Str.rfind(CharC->getSExtValue());
|
Str.size() : Str.rfind(CharC->getSExtValue());
|
||||||
if (I == StringRef::npos) // Didn't find the char. Return null.
|
if (I == StringRef::npos) // Didn't find the char. Return null.
|
||||||
return Constant::getNullValue(CI->getType());
|
return Constant::getNullValue(CI->getType());
|
||||||
|
@ -52,3 +52,14 @@ define void @test_simplify4(i32 %chr) {
|
|||||||
store i8* %dst, i8** @chp
|
store i8* %dst, i8** @chp
|
||||||
ret void
|
ret void
|
||||||
}
|
}
|
||||||
|
|
||||||
|
define void @test_simplify5() {
|
||||||
|
; CHECK: store i8* getelementptr inbounds ([14 x i8]* @hello, i32 0, i32 13)
|
||||||
|
; CHECK-NOT: call i8* @strchr
|
||||||
|
; CHECK: ret void
|
||||||
|
|
||||||
|
%src = getelementptr [14 x i8]* @hello, i32 0, i32 0
|
||||||
|
%dst = call i8* @strchr(i8* %src, i32 65280)
|
||||||
|
store i8* %dst, i8** @chp
|
||||||
|
ret void
|
||||||
|
}
|
||||||
|
@ -42,6 +42,17 @@ define void @test_simplify3() {
|
|||||||
ret void
|
ret void
|
||||||
}
|
}
|
||||||
|
|
||||||
|
define void @test_simplify4() {
|
||||||
|
; CHECK: store i8* getelementptr inbounds ([14 x i8]* @hello, i32 0, i32 13)
|
||||||
|
; CHECK-NOT: call i8* @strrchr
|
||||||
|
; CHECK: ret void
|
||||||
|
|
||||||
|
%src = getelementptr [14 x i8]* @hello, i32 0, i32 0
|
||||||
|
%dst = call i8* @strrchr(i8* %src, i32 65280)
|
||||||
|
store i8* %dst, i8** @chp
|
||||||
|
ret void
|
||||||
|
}
|
||||||
|
|
||||||
define void @test_nosimplify1(i32 %chr) {
|
define void @test_nosimplify1(i32 %chr) {
|
||||||
; CHECK-LABEL: @test_nosimplify1(
|
; CHECK-LABEL: @test_nosimplify1(
|
||||||
; CHECK: call i8* @strrchr
|
; CHECK: call i8* @strrchr
|
||||||
|
Loading…
Reference in New Issue
Block a user