blob: 90b4173ced7778b9655e1aa1e575c521de9e0ed5 [file] [log] [blame]
Meador Inge7fbc3642012-09-27 21:21:31 +00001; Test lib call simplification of __strncpy_chk calls with various values
2; for len and dstlen.
3;
4; RUN: opt < %s -instcombine -S | FileCheck %s
5
6target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128"
7
8@a = common global [60 x i8] zeroinitializer, align 1
9@b = common global [60 x i8] zeroinitializer, align 1
Meador Inge067294b2012-10-31 03:33:00 +000010@.str = private constant [12 x i8] c"abcdefghijk\00"
Meador Inge7fbc3642012-09-27 21:21:31 +000011
12; Check cases where dstlen >= len
13
14define void @test_simplify1() {
Stephen Linc1c7a132013-07-14 01:42:54 +000015; CHECK-LABEL: @test_simplify1(
Meador Inge7fbc3642012-09-27 21:21:31 +000016 %dst = getelementptr inbounds [60 x i8]* @a, i32 0, i32 0
Meador Inge067294b2012-10-31 03:33:00 +000017 %src = getelementptr inbounds [12 x i8]* @.str, i32 0, i32 0
Meador Inge7fbc3642012-09-27 21:21:31 +000018
Meador Inge067294b2012-10-31 03:33:00 +000019; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i32
20 call i8* @__strncpy_chk(i8* %dst, i8* %src, i32 12, i32 60)
Meador Inge7fbc3642012-09-27 21:21:31 +000021 ret void
22}
23
24define void @test_simplify2() {
Stephen Linc1c7a132013-07-14 01:42:54 +000025; CHECK-LABEL: @test_simplify2(
Meador Inge7fbc3642012-09-27 21:21:31 +000026 %dst = getelementptr inbounds [60 x i8]* @a, i32 0, i32 0
Meador Inge067294b2012-10-31 03:33:00 +000027 %src = getelementptr inbounds [12 x i8]* @.str, i32 0, i32 0
Meador Inge7fbc3642012-09-27 21:21:31 +000028
Meador Inge067294b2012-10-31 03:33:00 +000029; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i32
30 call i8* @__strncpy_chk(i8* %dst, i8* %src, i32 12, i32 12)
Meador Inge7fbc3642012-09-27 21:21:31 +000031 ret void
32}
33
34define void @test_simplify3() {
Stephen Linc1c7a132013-07-14 01:42:54 +000035; CHECK-LABEL: @test_simplify3(
Meador Inge7fbc3642012-09-27 21:21:31 +000036 %dst = getelementptr inbounds [60 x i8]* @a, i32 0, i32 0
37 %src = getelementptr inbounds [60 x i8]* @b, i32 0, i32 0
38
39; CHECK-NEXT: call i8* @strncpy
Meador Inge067294b2012-10-31 03:33:00 +000040 call i8* @__strncpy_chk(i8* %dst, i8* %src, i32 12, i32 60)
Meador Inge7fbc3642012-09-27 21:21:31 +000041 ret void
42}
43
44; Check cases where dstlen < len
45
46define void @test_no_simplify1() {
Stephen Linc1c7a132013-07-14 01:42:54 +000047; CHECK-LABEL: @test_no_simplify1(
Meador Inge7fbc3642012-09-27 21:21:31 +000048 %dst = getelementptr inbounds [60 x i8]* @a, i32 0, i32 0
Meador Inge067294b2012-10-31 03:33:00 +000049 %src = getelementptr inbounds [12 x i8]* @.str, i32 0, i32 0
Meador Inge7fbc3642012-09-27 21:21:31 +000050
51; CHECK-NEXT: call i8* @__strncpy_chk
52 call i8* @__strncpy_chk(i8* %dst, i8* %src, i32 8, i32 4)
53 ret void
54}
55
56define void @test_no_simplify2() {
Stephen Linc1c7a132013-07-14 01:42:54 +000057; CHECK-LABEL: @test_no_simplify2(
Meador Inge7fbc3642012-09-27 21:21:31 +000058 %dst = getelementptr inbounds [60 x i8]* @a, i32 0, i32 0
59 %src = getelementptr inbounds [60 x i8]* @b, i32 0, i32 0
60
61; CHECK-NEXT: call i8* @__strncpy_chk
62 call i8* @__strncpy_chk(i8* %dst, i8* %src, i32 8, i32 0)
63 ret void
64}
65
66declare i8* @__strncpy_chk(i8*, i8*, i32, i32)