Skip to content

Commit 7a3f916

Browse files
committed
[DSE] Add tests for __memset_chk libcalls.
1 parent d068e29 commit 7a3f916

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

llvm/test/Transforms/DeadStoreElimination/libcalls-chk.ll

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
target triple = "x86_64-unknown-linux-gnu"
55

66
declare ptr @__memset_chk(ptr writeonly, i32, i64, i64) argmemonly
7+
declare ptr @__memcpy_chk(ptr writeonly, ptr readonly, i64, i64) argmemonly nounwind
8+
79
declare ptr @strncpy(ptr %dest, ptr %src, i64 %n) nounwind
810
declare void @use(ptr)
911

@@ -106,3 +108,27 @@ define void @dse_strncpy_chk_test3(ptr noalias %out1, ptr noalias %out2, ptr noa
106108
%call.2 = tail call ptr @__memset_chk(ptr %out2, i32 42, i64 100, i64 %n)
107109
ret void
108110
}
111+
112+
define void @dse_strncpy_memcpy_chk_test1(ptr noalias %out, ptr noalias %in, i64 %n) {
113+
; CHECK-LABEL: @dse_strncpy_memcpy_chk_test1(
114+
; CHECK-NEXT: store i32 0, ptr [[OUT:%.*]], align 4
115+
; CHECK-NEXT: [[CALL_1:%.*]] = tail call ptr @__memcpy_chk(ptr [[OUT]], ptr [[IN:%.*]], i64 100, i64 [[N:%.*]])
116+
; CHECK-NEXT: ret void
117+
;
118+
store i32 0, ptr %out
119+
%call.1 = tail call ptr @__memcpy_chk(ptr %out, ptr %in, i64 100, i64 %n)
120+
ret void
121+
}
122+
123+
define void @dse_strncpy_memcpy_chk_test2(ptr noalias %out, ptr noalias %in, i64 %n) {
124+
; CHECK-LABEL: @dse_strncpy_memcpy_chk_test2(
125+
; CHECK-NEXT: [[GEP:%.*]] = getelementptr inbounds i8, ptr [[OUT:%.*]], i64 100
126+
; CHECK-NEXT: store i8 10, ptr [[GEP]], align 1
127+
; CHECK-NEXT: [[CALL_1:%.*]] = tail call ptr @__memcpy_chk(ptr [[OUT]], ptr [[IN:%.*]], i64 100, i64 [[N:%.*]])
128+
; CHECK-NEXT: ret void
129+
;
130+
%gep = getelementptr inbounds i8, ptr %out, i64 100
131+
store i8 10, ptr %gep
132+
%call.1 = tail call ptr @__memcpy_chk(ptr %out, ptr %in, i64 100, i64 %n)
133+
ret void
134+
}

0 commit comments

Comments
 (0)