1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-22 10:42:39 +01:00

DSE: fix bug where we would only check libcalls for name rather than whole decl

This commit is contained in:
Nuno Lopes 2020-01-11 11:57:29 +00:00
parent 9a6b5ddc4c
commit e59e19e267
3 changed files with 32 additions and 13 deletions

View File

@ -179,15 +179,18 @@ static bool hasAnalyzableMemoryWrite(Instruction *I,
}
if (auto CS = CallSite(I)) {
if (Function *F = CS.getCalledFunction()) {
StringRef FnName = F->getName();
if (TLI.has(LibFunc_strcpy) && FnName == TLI.getName(LibFunc_strcpy))
return true;
if (TLI.has(LibFunc_strncpy) && FnName == TLI.getName(LibFunc_strncpy))
return true;
if (TLI.has(LibFunc_strcat) && FnName == TLI.getName(LibFunc_strcat))
return true;
if (TLI.has(LibFunc_strncat) && FnName == TLI.getName(LibFunc_strncat))
return true;
LibFunc LF;
if (TLI.getLibFunc(*F, LF) && TLI.has(LF)) {
switch (LF) {
case LibFunc_strcpy:
case LibFunc_strncpy:
case LibFunc_strcat:
case LibFunc_strncat:
return true;
default:
return false;
}
}
}
}
return false;

View File

@ -1,5 +1,7 @@
; RUN: opt -S -basicaa -dse < %s | FileCheck %s
target triple = "x86_64-unknown-linux-gnu"
declare i8* @strcpy(i8* %dest, i8* %src) nounwind
define void @test1(i8* %src) {
; CHECK-LABEL: @test1(
@ -11,13 +13,13 @@ define void @test1(i8* %src) {
ret void
}
declare i8* @strncpy(i8* %dest, i8* %src, i32 %n) nounwind
declare i8* @strncpy(i8* %dest, i8* %src, i64 %n) nounwind
define void @test2(i8* %src) {
; CHECK-LABEL: @test2(
%B = alloca [16 x i8]
%dest = getelementptr inbounds [16 x i8], [16 x i8]* %B, i64 0, i64 0
; CHECK-NOT: @strncpy
%call = call i8* @strncpy(i8* %dest, i8* %src, i32 12)
%call = call i8* @strncpy(i8* %dest, i8* %src, i64 12)
; CHECK: ret void
ret void
}
@ -33,13 +35,13 @@ define void @test3(i8* %src) {
ret void
}
declare i8* @strncat(i8* %dest, i8* %src, i32 %n) nounwind
declare i8* @strncat(i8* %dest, i8* %src, i64 %n) nounwind
define void @test4(i8* %src) {
; CHECK-LABEL: @test4(
%B = alloca [16 x i8]
%dest = getelementptr inbounds [16 x i8], [16 x i8]* %B, i64 0, i64 0
; CHECK-NOT: @strncat
%call = call i8* @strncat(i8* %dest, i8* %src, i32 12)
%call = call i8* @strncat(i8* %dest, i8* %src, i64 12)
; CHECK: ret void
ret void
}

View File

@ -0,0 +1,14 @@
; RUN: opt -S -basicaa -dse < %s | FileCheck %s
target triple = "x86_64-unknown-linux-gnu"
declare i8* @strncpy(i8* %dest, i8* %src, i32 %n) nounwind
define void @test2(i8* %src) {
; CHECK-LABEL: @test2(
%B = alloca [16 x i8]
%dest = getelementptr inbounds [16 x i8], [16 x i8]* %B, i64 0, i64 0
; CHECK: @strncpy
%call = call i8* @strncpy(i8* %dest, i8* %src, i32 12)
; CHECK: ret void
ret void
}