Skip to content

Commit 26cdc62

Browse files
committed
Add printf test cases
1 parent 92c7c20 commit 26cdc62

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// RUN: %clang_cc1 -std=c++11 -triple x86_64-unknown-linux-gnu -Wno-unused-value -fclangir -emit-cir %s -o %t.cir
2+
// RUN: FileCheck --input-file=%t.cir %s -check-prefix=CIR
3+
// RUN: %clang_cc1 -std=c++11 -triple x86_64-unknown-linux-gnu -Wno-unused-value -fclangir -emit-llvm %s -o %t-cir.ll
4+
// RUN: FileCheck --input-file=%t-cir.ll %s -check-prefix=LLVM
5+
// RUN: %clang_cc1 -std=c++11 -triple x86_64-unknown-linux-gnu -Wno-unused-value -emit-llvm %s -o %t.ll
6+
// RUN: FileCheck --input-file=%t.ll %s -check-prefix=OGCG
7+
8+
// CIR: cir.global "private" cir_private dsolocal @".str" = #cir.const_array<"%s\00" : !cir.array<!s8i x 3>> : !cir.array<!s8i x 3>
9+
// CIR: cir.global "private" cir_private dsolocal @".str.1" = #cir.const_array<"%s %d\0A\00" : !cir.array<!s8i x 7>> : !cir.array<!s8i x 7>
10+
// LLVM: @.str = private global [3 x i8] c"%s\00"
11+
// LLVM: @.str.1 = private global [7 x i8] c"%s %d\0A\00"
12+
// OGCG: @.str = private unnamed_addr constant [3 x i8] c"%s\00"
13+
// OGCG: @.str.1 = private unnamed_addr constant [7 x i8] c"%s %d\0A\00"
14+
15+
void func(char const * const str, int i) {
16+
__builtin_printf(nullptr);
17+
__builtin_printf("%s", str);
18+
__builtin_printf("%s %d\n", str, i);
19+
}
20+
21+
// CIR: cir.func @_Z4funcPKci(%[[arg0:.+]]: !cir.ptr<!s8i>{{.*}}, %[[arg1:.+]]: !s32i{{.*}}) {
22+
// CIR: %[[str_ptr:.+]] = cir.alloca !cir.ptr<!s8i>, !cir.ptr<!cir.ptr<!s8i>>, ["str", init, const]
23+
// CIR: %[[i_ptr:.+]] = cir.alloca !s32i, !cir.ptr<!s32i>, ["i", init]
24+
// CIR: cir.store %[[arg0]], %[[str_ptr]] : !cir.ptr<!s8i>, !cir.ptr<!cir.ptr<!s8i>>
25+
// CIR: cir.store %[[arg1]], %[[i_ptr]] : !s32i, !cir.ptr<!s32i>
26+
// CIR: %[[null_ptr:.+]] = cir.const #cir.ptr<null> : !cir.ptr<!s8i>
27+
// CIR: %[[printf_result1:.+]] = cir.call @printf(%[[null_ptr]]) : (!cir.ptr<!s8i>) -> !s32i
28+
// CIR: %[[str_fmt_global:.+]] = cir.get_global @".str" : !cir.ptr<!cir.array<!s8i x 3>>
29+
// CIR: %[[str_fmt_ptr:.+]] = cir.cast(array_to_ptrdecay, %[[str_fmt_global]] : !cir.ptr<!cir.array<!s8i x 3>>), !cir.ptr<!s8i>
30+
// CIR: %[[str_val:.+]] = cir.load{{.*}} %[[str_ptr]] : !cir.ptr<!cir.ptr<!s8i>>, !cir.ptr<!s8i>
31+
// CIR: %[[printf_result2:.+]] = cir.call @printf(%[[str_fmt_ptr]], %[[str_val]]) : (!cir.ptr<!s8i>, !cir.ptr<!s8i>) -> !s32i
32+
// CIR: %[[full_fmt_global:.+]] = cir.get_global @".str.1" : !cir.ptr<!cir.array<!s8i x 7>>
33+
// CIR: %[[full_fmt_ptr:.+]] = cir.cast(array_to_ptrdecay, %[[full_fmt_global]] : !cir.ptr<!cir.array<!s8i x 7>>), !cir.ptr<!s8i>
34+
// CIR: %[[str_val2:.+]] = cir.load{{.*}} %[[str_ptr]] : !cir.ptr<!cir.ptr<!s8i>>, !cir.ptr<!s8i>
35+
// CIR: %[[i_val:.+]] = cir.load{{.*}} %[[i_ptr]] : !cir.ptr<!s32i>, !s32i
36+
// CIR: %[[printf_result3:.+]] = cir.call @printf(%[[full_fmt_ptr]], %[[str_val2]], %[[i_val]]) : (!cir.ptr<!s8i>, !cir.ptr<!s8i>, !s32i) -> !s32i
37+
// CIR: cir.return
38+
39+
// LLVM: define void @_Z4funcPKci(ptr %[[arg0:.+]], i32 %[[arg1:.+]])
40+
// LLVM: %[[str_ptr:.+]] = alloca ptr
41+
// LLVM: %[[i_ptr:.+]] = alloca i32
42+
// LLVM: store ptr %[[arg0]], ptr %[[str_ptr]]{{.*}}
43+
// LLVM: store i32 %[[arg1]], ptr %[[i_ptr]]{{.*}}
44+
// LLVM: %[[printf_result1:.+]] = call i32 (ptr, ...) @printf(ptr null)
45+
// LLVM: %[[str_val:.+]] = load ptr, ptr %[[str_ptr]]{{.*}}
46+
// LLVM: %[[printf_result2:.+]] = call i32 (ptr, ...) @printf(ptr @.str, ptr %[[str_val]])
47+
// LLVM: %[[str_val2:.+]] = load ptr, ptr %[[str_ptr]]{{.*}}
48+
// LLVM: %[[i_val:.+]] = load i32, ptr %[[i_ptr]]{{.*}}
49+
// LLVM: %[[printf_result3:.+]] = call i32 (ptr, ...) @printf(ptr @.str.1, ptr %[[str_val2]], i32 %[[i_val]])
50+
// LLVM: ret void
51+
52+
// OGCG: define dso_local void @_Z4funcPKci(ptr noundef %[[arg0:.+]], i32 noundef %[[arg1:.+]])
53+
// OGCG: %[[str_ptr:.+]] = alloca ptr
54+
// OGCG: %[[i_ptr:.+]] = alloca i32
55+
// OGCG: store ptr %[[arg0]], ptr %[[str_ptr]]{{.*}}
56+
// OGCG: store i32 %[[arg1]], ptr %[[i_ptr]]{{.*}}
57+
// OGCG: %[[printf_result1:.+]] = call i32 (ptr, ...) @printf(ptr noundef null)
58+
// OGCG: %[[str_val:.+]] = load ptr, ptr %[[str_ptr]]{{.*}}
59+
// OGCG: %[[printf_result2:.+]] = call i32 (ptr, ...) @printf(ptr noundef @.str, ptr noundef %[[str_val]])
60+
// OGCG: %[[str_val2:.+]] = load ptr, ptr %[[str_ptr]]{{.*}}
61+
// OGCG: %[[i_val:.+]] = load i32, ptr %[[i_ptr]]{{.*}}
62+
// OGCG: %[[printf_result3:.+]] = call i32 (ptr, ...) @printf(ptr noundef @.str.1, ptr noundef %[[str_val2]], i32 noundef %[[i_val]])
63+
// OGCG: ret void

0 commit comments

Comments
 (0)