1; Test that __strlen_chk simplification works correctly.
2;
3; RUN: opt < %s -instcombine -S | FileCheck %s
4
5target 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"
6
7@hello = constant [6 x i8] c"hello\00"
8@hello_no_nul = constant [5 x i8] c"hello"
9
10declare i32 @__strlen_chk(i8*, i32)
11
12; Check __strlen_chk(string constant) -> strlen or constants
13
14; CHECK-LABEL: @unknown_str_known_object_size
15define i32 @unknown_str_known_object_size(i8* %c) {
16  ; CHECK: call i32 @__strlen_chk
17  %1 = call i32 @__strlen_chk(i8* %c, i32 8)
18  ret i32 %1
19}
20
21; CHECK-LABEL: @known_str_known_object_size
22define i32 @known_str_known_object_size(i8* %c) {
23  ; CHECK: ret i32 5
24  %1 = call i32 @__strlen_chk(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @hello, i32 0, i32 0), i32 6)
25  ret i32 %1
26}
27
28; CHECK-LABEL: @known_str_too_small_object_size
29define i32 @known_str_too_small_object_size(i8* %c) {
30  ; CHECK: call i32 @__strlen_chk
31  %1 = call i32 @__strlen_chk(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @hello, i32 0, i32 0), i32 5)
32  ret i32 %1
33}
34
35; CHECK-LABEL: @known_str_no_nul
36define i32 @known_str_no_nul(i8* %c) {
37  ; CHECK: call i32 @__strlen_chk
38  %1 = call i32 @__strlen_chk(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @hello_no_nul, i32 0, i32 0), i32 5)
39  ret i32 %1
40}
41
42; CHECK-LABEL: @unknown_str_unknown_object_size
43define i32 @unknown_str_unknown_object_size(i8* %c) {
44  ; CHECK: call i32 @strlen
45  %1 = call i32 @__strlen_chk(i8* %c, i32 -1)
46  ret i32 %1
47}
48