1 ; RUN: opt < %s -instcombine -S | FileCheck %s --dump-input-on-failure
3 target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
5 @a = common global [60 x i8] zeroinitializer, align 1
6 @b = common global [60 x i8] zeroinitializer, align 1
7 @.str = private constant [12 x i8] c"abcdefghijk\00"
9 %struct.__va_list_tag = type { i32, i32, i8*, i8* }
11 define i8* @test_memccpy() {
12 ; CHECK-LABEL: define i8* @test_memccpy
13 ; CHECK-NEXT: call i8* @memccpy(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @a, i64 0, i64 0), i8* getelementptr inbounds ([60 x i8], [60 x i8]* @b, i64 0, i64 0), i32 0, i64 60)
15 %dst = getelementptr inbounds [60 x i8], [60 x i8]* @a, i32 0, i32 0
16 %src = getelementptr inbounds [60 x i8], [60 x i8]* @b, i32 0, i32 0
17 %ret = call i8* @__memccpy_chk(i8* %dst, i8* %src, i32 0, i64 60, i64 -1)
21 define i8* @test_not_memccpy() {
22 ; CHECK-LABEL: define i8* @test_not_memccpy
23 ; CHECK-NEXT: call i8* @__memccpy_chk
25 %dst = getelementptr inbounds [60 x i8], [60 x i8]* @a, i32 0, i32 0
26 %src = getelementptr inbounds [60 x i8], [60 x i8]* @b, i32 0, i32 0
27 %ret = call i8* @__memccpy_chk(i8* %dst, i8* %src, i32 0, i64 60, i64 59)
31 define i32 @test_snprintf() {
32 ; CHECK-LABEL: define i32 @test_snprintf
33 ; CHECK-NEXT: call i32 (i8*, i64, i8*, ...) @snprintf(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @a, i64 0, i64 0), i64 60, i8* getelementptr inbounds ([60 x i8], [60 x i8]* @b, i64 0, i64 0))
35 %dst = getelementptr inbounds [60 x i8], [60 x i8]* @a, i32 0, i32 0
36 %fmt = getelementptr inbounds [60 x i8], [60 x i8]* @b, i32 0, i32 0
37 %ret = call i32 (i8*, i64, i32, i64, i8*, ...) @__snprintf_chk(i8* %dst, i64 60, i32 0, i64 -1, i8* %fmt)
41 define i32 @test_not_snprintf() {
42 ; CHECK-LABEL: define i32 @test_not_snprintf
43 ; CHECK-NEXT: call i32 (i8*, i64, i32, i64, i8*, ...) @__snprintf_chk
44 ; CHECK-NEXT: call i32 (i8*, i64, i32, i64, i8*, ...) @__snprintf_chk
46 %dst = getelementptr inbounds [60 x i8], [60 x i8]* @a, i32 0, i32 0
47 %fmt = getelementptr inbounds [60 x i8], [60 x i8]* @b, i32 0, i32 0
48 %ret = call i32 (i8*, i64, i32, i64, i8*, ...) @__snprintf_chk(i8* %dst, i64 60, i32 0, i64 59, i8* %fmt)
49 %ign = call i32 (i8*, i64, i32, i64, i8*, ...) @__snprintf_chk(i8* %dst, i64 60, i32 1, i64 -1, i8* %fmt)
53 define i32 @test_sprintf() {
54 ; CHECK-LABEL: define i32 @test_sprintf
55 ; CHECK-NEXT: call i32 (i8*, i8*, ...) @sprintf(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @a, i64 0, i64 0), i8* getelementptr inbounds ([60 x i8], [60 x i8]* @b, i64 0, i64 0))
57 %dst = getelementptr inbounds [60 x i8], [60 x i8]* @a, i32 0, i32 0
58 %fmt = getelementptr inbounds [60 x i8], [60 x i8]* @b, i32 0, i32 0
59 %ret = call i32 (i8*, i32, i64, i8*, ...) @__sprintf_chk(i8* %dst, i32 0, i64 -1, i8* %fmt)
63 define i32 @test_not_sprintf() {
64 ; CHECK-LABEL: define i32 @test_not_sprintf
65 ; CHECK-NEXT: call i32 (i8*, i32, i64, i8*, ...) @__sprintf_chk
66 ; CHECK-NEXT: call i32 (i8*, i32, i64, i8*, ...) @__sprintf_chk
68 %dst = getelementptr inbounds [60 x i8], [60 x i8]* @a, i32 0, i32 0
69 %fmt = getelementptr inbounds [60 x i8], [60 x i8]* @b, i32 0, i32 0
70 %ret = call i32 (i8*, i32, i64, i8*, ...) @__sprintf_chk(i8* %dst, i32 0, i64 59, i8* %fmt)
71 %ignored = call i32 (i8*, i32, i64, i8*, ...) @__sprintf_chk(i8* %dst, i32 1, i64 -1, i8* %fmt)
75 define i8* @test_strcat() {
76 ; CHECK-LABEL: define i8* @test_strcat
77 ; CHECK-NEXT: call i8* @strcat(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @a, i64 0, i64 0), i8* getelementptr inbounds ([60 x i8], [60 x i8]* @b, i64 0, i64 0))
79 %dst = getelementptr inbounds [60 x i8], [60 x i8]* @a, i32 0, i32 0
80 %src = getelementptr inbounds [60 x i8], [60 x i8]* @b, i32 0, i32 0
81 %ret = call i8* @__strcat_chk(i8* %dst, i8* %src, i64 -1)
85 define i8* @test_not_strcat() {
86 ; CHECK-LABEL: define i8* @test_not_strcat
87 ; CHECK-NEXT: call i8* @__strcat_chk
89 %dst = getelementptr inbounds [60 x i8], [60 x i8]* @a, i32 0, i32 0
90 %src = getelementptr inbounds [60 x i8], [60 x i8]* @b, i32 0, i32 0
91 %ret = call i8* @__strcat_chk(i8* %dst, i8* %src, i64 0)
95 define i64 @test_strlcat() {
96 ; CHECK-LABEL: define i64 @test_strlcat
97 ; CHECK-NEXT: call i64 @strlcat(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @a, i64 0, i64 0), i8* getelementptr inbounds ([60 x i8], [60 x i8]* @b, i64 0, i64 0), i64 22)
99 %dst = getelementptr inbounds [60 x i8], [60 x i8]* @a, i32 0, i32 0
100 %src = getelementptr inbounds [60 x i8], [60 x i8]* @b, i32 0, i32 0
101 %ret = call i64 @__strlcat_chk(i8* %dst, i8* %src, i64 22, i64 -1)
105 define i64 @test_not_strlcat() {
106 ; CHECK-LABEL: define i64 @test_not_strlcat
107 ; CHECK-NEXT: call i64 @__strlcat_chk
108 ; CHECK-NEXT: ret i64
109 %dst = getelementptr inbounds [60 x i8], [60 x i8]* @a, i32 0, i32 0
110 %src = getelementptr inbounds [60 x i8], [60 x i8]* @b, i32 0, i32 0
111 %ret = call i64 @__strlcat_chk(i8* %dst, i8* %src, i64 22, i64 0)
115 define i8* @test_strncat() {
116 ; CHECK-LABEL: define i8* @test_strncat
117 ; CHECK-NEXT: call i8* @strncat(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @a, i64 0, i64 0), i8* getelementptr inbounds ([60 x i8], [60 x i8]* @b, i64 0, i64 0), i64 22)
118 ; CHECK-NEXT: ret i8*
119 %dst = getelementptr inbounds [60 x i8], [60 x i8]* @a, i32 0, i32 0
120 %src = getelementptr inbounds [60 x i8], [60 x i8]* @b, i32 0, i32 0
121 %ret = call i8* @__strncat_chk(i8* %dst, i8* %src, i64 22, i64 -1)
125 define i8* @test_not_strncat() {
126 ; CHECK-LABEL: define i8* @test_not_strncat
127 ; CHECK-NEXT: call i8* @__strncat_chk(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @a, i64 0, i64 0), i8* getelementptr inbounds ([60 x i8], [60 x i8]* @b, i64 0, i64 0), i64 22, i64 3)
128 ; CHECK-NEXT: ret i8*
129 %dst = getelementptr inbounds [60 x i8], [60 x i8]* @a, i32 0, i32 0
130 %src = getelementptr inbounds [60 x i8], [60 x i8]* @b, i32 0, i32 0
131 %ret = call i8* @__strncat_chk(i8* %dst, i8* %src, i64 22, i64 3)
135 define i64 @test_strlcpy() {
136 ; CHECK-LABEL: define i64 @test_strlcpy
137 ; CHECK-NEXT: call i64 @strlcpy(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @a, i64 0, i64 0), i8* getelementptr inbounds ([60 x i8], [60 x i8]* @b, i64 0, i64 0), i64 22)
138 ; CHECK-NEXT: ret i64
139 %dst = getelementptr inbounds [60 x i8], [60 x i8]* @a, i32 0, i32 0
140 %src = getelementptr inbounds [60 x i8], [60 x i8]* @b, i32 0, i32 0
141 %ret = call i64 @__strlcpy_chk(i8* %dst, i8* %src, i64 22, i64 -1)
145 define i64 @test_not_strlcpy() {
146 ; CHECK-LABEL: define i64 @test_not_strlcpy
147 ; CHECK-NEXT: call i64 @__strlcpy_chk(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @a, i64 0, i64 0), i8* getelementptr inbounds ([60 x i8], [60 x i8]* @b, i64 0, i64 0), i64 22, i64 2)
148 ; CHECK-NEXT: ret i64
149 %dst = getelementptr inbounds [60 x i8], [60 x i8]* @a, i32 0, i32 0
150 %src = getelementptr inbounds [60 x i8], [60 x i8]* @b, i32 0, i32 0
151 %ret = call i64 @__strlcpy_chk(i8* %dst, i8* %src, i64 22, i64 2)
155 define i32 @test_vsnprintf() {
156 ; CHECK-LABEL: define i32 @test_vsnprintf
157 ; CHECK-NEXT: call i32 @vsnprintf(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @a, i64 0, i64 0), i64 4, i8* getelementptr inbounds ([60 x i8], [60 x i8]* @b, i64 0, i64 0), %struct.__va_list_tag* null)
159 %dst = getelementptr inbounds [60 x i8], [60 x i8]* @a, i32 0, i32 0
160 %src = getelementptr inbounds [60 x i8], [60 x i8]* @b, i32 0, i32 0
161 %ret = call i32 @__vsnprintf_chk(i8* %dst, i64 4, i32 0, i64 -1, i8* %src, %struct.__va_list_tag* null)
165 define i32 @test_not_vsnprintf() {
166 ; CHECK-LABEL: define i32 @test_not_vsnprintf
167 ; CHECK-NEXT: call i32 @__vsnprintf_chk(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @a, i64 0, i64 0), i64 4, i32 0, i64 3, i8* getelementptr inbounds ([60 x i8], [60 x i8]* @b, i64 0, i64 0), %struct.__va_list_tag* null)
168 ; CHECK-NEXT: call i32 @__vsnprintf_chk(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @a, i64 0, i64 0), i64 4, i32 1, i64 -1, i8* getelementptr inbounds ([60 x i8], [60 x i8]* @b, i64 0, i64 0), %struct.__va_list_tag* null)
170 %dst = getelementptr inbounds [60 x i8], [60 x i8]* @a, i32 0, i32 0
171 %src = getelementptr inbounds [60 x i8], [60 x i8]* @b, i32 0, i32 0
172 %ret = call i32 @__vsnprintf_chk(i8* %dst, i64 4, i32 0, i64 3, i8* %src, %struct.__va_list_tag* null)
173 %ign = call i32 @__vsnprintf_chk(i8* %dst, i64 4, i32 1, i64 -1, i8* %src, %struct.__va_list_tag* null)
177 define i32 @test_vsprintf() {
178 ; CHECK-LABEL: define i32 @test_vsprintf
179 ; CHECK-NEXT: call i32 @vsprintf(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @a, i64 0, i64 0), i8* getelementptr inbounds ([60 x i8], [60 x i8]* @b, i64 0, i64 0), %struct.__va_list_tag* null)
181 %dst = getelementptr inbounds [60 x i8], [60 x i8]* @a, i32 0, i32 0
182 %src = getelementptr inbounds [60 x i8], [60 x i8]* @b, i32 0, i32 0
183 %ret = call i32 @__vsprintf_chk(i8* %dst, i32 0, i64 -1, i8* %src, %struct.__va_list_tag* null)
187 define i32 @test_not_vsprintf() {
188 ; CHECK-LABEL: define i32 @test_not_vsprintf
189 ; CHECK-NEXT: call i32 @__vsprintf_chk(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @a, i64 0, i64 0), i32 0, i64 3, i8* getelementptr inbounds ([60 x i8], [60 x i8]* @b, i64 0, i64 0), %struct.__va_list_tag* null)
190 ; CHECK-NEXT: call i32 @__vsprintf_chk(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @a, i64 0, i64 0), i32 1, i64 -1, i8* getelementptr inbounds ([60 x i8], [60 x i8]* @b, i64 0, i64 0), %struct.__va_list_tag* null)
192 %dst = getelementptr inbounds [60 x i8], [60 x i8]* @a, i32 0, i32 0
193 %src = getelementptr inbounds [60 x i8], [60 x i8]* @b, i32 0, i32 0
194 %ret = call i32 @__vsprintf_chk(i8* %dst, i32 0, i64 3, i8* %src, %struct.__va_list_tag* null)
195 %ign = call i32 @__vsprintf_chk(i8* %dst, i32 1, i64 -1, i8* %src, %struct.__va_list_tag* null)
199 declare i8* @__memccpy_chk(i8*, i8*, i32, i64, i64)
200 declare i32 @__snprintf_chk(i8*, i64, i32, i64, i8*, ...)
201 declare i32 @__sprintf_chk(i8*, i32, i64, i8*, ...)
202 declare i8* @__strcat_chk(i8*, i8*, i64)
203 declare i64 @__strlcat_chk(i8*, i8*, i64, i64)
204 declare i8* @__strncat_chk(i8*, i8*, i64, i64)
205 declare i64 @__strlcpy_chk(i8*, i8*, i64, i64)
206 declare i32 @__vsnprintf_chk(i8*, i64, i32, i64, i8*, %struct.__va_list_tag*)
207 declare i32 @__vsprintf_chk(i8*, i32, i64, i8*, %struct.__va_list_tag*)