1 ; Test lib call simplification of __strncpy_chk calls with various values
4 ; RUN: opt < %s -instcombine -S | FileCheck %s
6 target 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"
8 @a = common global [60 x i8] zeroinitializer, align 1
9 @b = common global [60 x i8] zeroinitializer, align 1
10 @.str = private constant [12 x i8] c"abcdefghijk\00"
12 ; Check cases where dstlen >= len
14 define void @test_simplify1() {
15 ; CHECK-LABEL: @test_simplify1(
16 %dst = getelementptr inbounds [60 x i8]* @a, i32 0, i32 0
17 %src = getelementptr inbounds [12 x i8]* @.str, i32 0, i32 0
19 ; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i32
20 call i8* @__strncpy_chk(i8* %dst, i8* %src, i32 12, i32 60)
24 define void @test_simplify2() {
25 ; CHECK-LABEL: @test_simplify2(
26 %dst = getelementptr inbounds [60 x i8]* @a, i32 0, i32 0
27 %src = getelementptr inbounds [12 x i8]* @.str, i32 0, i32 0
29 ; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i32
30 call i8* @__strncpy_chk(i8* %dst, i8* %src, i32 12, i32 12)
34 define void @test_simplify3() {
35 ; CHECK-LABEL: @test_simplify3(
36 %dst = getelementptr inbounds [60 x i8]* @a, i32 0, i32 0
37 %src = getelementptr inbounds [60 x i8]* @b, i32 0, i32 0
39 ; CHECK-NEXT: call i8* @strncpy
40 call i8* @__strncpy_chk(i8* %dst, i8* %src, i32 12, i32 60)
44 ; Check cases where dstlen < len
46 define void @test_no_simplify1() {
47 ; CHECK-LABEL: @test_no_simplify1(
48 %dst = getelementptr inbounds [60 x i8]* @a, i32 0, i32 0
49 %src = getelementptr inbounds [12 x i8]* @.str, i32 0, i32 0
51 ; CHECK-NEXT: call i8* @__strncpy_chk
52 call i8* @__strncpy_chk(i8* %dst, i8* %src, i32 8, i32 4)
56 define void @test_no_simplify2() {
57 ; CHECK-LABEL: @test_no_simplify2(
58 %dst = getelementptr inbounds [60 x i8]* @a, i32 0, i32 0
59 %src = getelementptr inbounds [60 x i8]* @b, i32 0, i32 0
61 ; CHECK-NEXT: call i8* @__strncpy_chk
62 call i8* @__strncpy_chk(i8* %dst, i8* %src, i32 8, i32 0)
66 declare i8* @__strncpy_chk(i8*, i8*, i32, i32)