Debian Codegraph @

clang/test/CIR/CodeGen/call.c

raw
1 // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o %t.cir
2 // RUN: FileCheck --input-file=%t.cir %s -check-prefix=CIR
3 // RUN: %clang_cc1 -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 -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 struct S {
9 int x;
10 int y;
11 };
12
13 void f1(struct S);
14 void f2(void) {
15 struct S s;
16 f1(s);
17 }
18
19 // CIR-LABEL: cir.func{{.*}} @f2(){{.*}} {
20 // CIR: %[[S:.+]] = cir.load align(4) %{{.+}} : !cir.ptr<!rec_S>, !rec_S
21 // CIR-NEXT: cir.call @f1(%[[S]]) : (!rec_S) -> ()
22
23 // LLVM-LABEL: define{{.*}} void @f2(){{.*}}
24 // LLVM: %[[S:.+]] = load %struct.S, ptr %{{.+}}, align 4
25 // LLVM-NEXT: call void @f1(%struct.S %[[S]])
26
27 // OGCG-LABEL: define{{.*}} void @f2()
28 // OGCG: %[[S:.+]] = load i64, ptr %{{.+}}, align 4
29 // OGCG-NEXT: call void @f1(i64 %[[S]])
30
31 struct S f3(void);
32 void f4(void) {
33 struct S s = f3();
34 }
35
36 // CIR-LABEL: cir.func{{.*}} @f4(){{.*}} {
37 // CIR: %[[S:.+]] = cir.call @f3() : () -> !rec_S
38 // CIR-NEXT: cir.store align(4) %[[S]], %{{.+}} : !rec_S, !cir.ptr<!rec_S>
39
40 // LLVM-LABEL: define{{.*}} void @f4(){{.*}} {
41 // LLVM: %[[S:.+]] = call %struct.S @f3()
42 // LLVM-NEXT: store %struct.S %[[S]], ptr %{{.+}}, align 4
43
44 // OGCG-LABEL: define{{.*}} void @f4() #0 {
45 // OGCG: %[[S:.+]] = call i64 @f3()
46 // OGCG-NEXT: store i64 %[[S]], ptr %{{.+}}, align 4
47
48 struct Big {
49 int data[10];
50 };
51
52 void f5(struct Big);
53 struct Big f6(void);
54
55 void f7(void) {
56 struct Big b;
57 f5(b);
58 }
59
60 // CIR-LABEL: cir.func{{.*}} @f7(){{.*}} {
61 // CIR: %[[B:.+]] = cir.load align(4) %{{.+}} : !cir.ptr<!rec_Big>, !rec_Big
62 // CIR-NEXT: cir.call @f5(%[[B]]) : (!rec_Big) -> ()
63
64 // LLVM-LABEL: define{{.*}} void @f7(){{.*}} {
65 // LLVM: %[[B:.+]] = load %struct.Big, ptr %{{.+}}, align 4
66 // LLVM-NEXT: call void @f5(%struct.Big %[[B]])
67
68 // OGCG-LABEL: define{{.*}} void @f7() #0 {
69 // OGCG: %[[B:.+]] = alloca %struct.Big, align 8
70 // OGCG-NEXT: call void @f5(ptr noundef byval(%struct.Big) align 8 %[[B]])
71
72 void f8(void) {
73 struct Big b = f6();
74 }
75
76 // CIR-LABEL: cir.func{{.*}} @f8(){{.*}} {
77 // CIR: %[[B:.+]] = cir.call @f6() : () -> !rec_Big
78 // CIR: cir.store align(4) %[[B]], %{{.+}} : !rec_Big, !cir.ptr<!rec_Big>
79
80 // LLVM-LABEL: define{{.*}} void @f8(){{.*}} {
81 // LLVM: %[[B:.+]] = call %struct.Big @f6()
82 // LLVM-NEXT: store %struct.Big %[[B]], ptr %{{.+}}, align 4
83
84 // OGCG-LABEL: define{{.*}} void @f8() #0 {
85 // OGCG: %[[B:.+]] = alloca %struct.Big, align 4
86 // OGCG-NEXT: call void @f6(ptr dead_on_unwind writable sret(%struct.Big) align 4 %[[B]])
87
88 void f9(void) {
89 f1(f3());
90 }
91
92 // CIR-LABEL: cir.func{{.*}} @f9(){{.*}} {
93 // CIR: %[[SLOT:.+]] = cir.alloca !rec_S, !cir.ptr<!rec_S>, ["agg.tmp0"] {alignment = 4 : i64}
94 // CIR-NEXT: %[[RET:.+]] = cir.call @f3() : () -> !rec_S
95 // CIR-NEXT: cir.store align(4) %[[RET]], %[[SLOT]] : !rec_S, !cir.ptr<!rec_S>
96 // CIR-NEXT: %[[ARG:.+]] = cir.load align(4) %[[SLOT]] : !cir.ptr<!rec_S>, !rec_S
97 // CIR-NEXT: cir.call @f1(%[[ARG]]) : (!rec_S) -> ()
98
99 // LLVM-LABEL: define{{.*}} void @f9(){{.*}} {
100 // LLVM: %[[SLOT:.+]] = alloca %struct.S, i64 1, align 4
101 // LLVM-NEXT: %[[RET:.+]] = call %struct.S @f3()
102 // LLVM-NEXT: store %struct.S %[[RET]], ptr %[[SLOT]], align 4
103 // LLVM-NEXT: %[[ARG:.+]] = load %struct.S, ptr %[[SLOT]], align 4
104 // LLVM-NEXT: call void @f1(%struct.S %[[ARG]])
105
106 // OGCG-LABEL: define{{.*}} void @f9() #0 {
107 // OGCG: %[[SLOT:.+]] = alloca %struct.S, align 4
108 // OGCG-NEXT: %[[RET:.+]] = call i64 @f3()
109 // OGCG-NEXT: store i64 %[[RET]], ptr %[[SLOT]], align 4
110 // OGCG-NEXT: %[[ARG:.+]] = load i64, ptr %[[SLOT]], align 4
111 // OGCG-NEXT: call void @f1(i64 %[[ARG]])
112
113 __attribute__((pure)) int f10(int);
114 __attribute__((const)) int f11(int);
115 int f12(void) {
116 return f10(1) + f11(2);
117 }
118
119 // CIR-LABEL: cir.func{{.*}} @f12() -> !s32i{{.*}} {
120 // CIR: %[[A:.+]] = cir.const #cir.int<1> : !s32i
121 // CIR-NEXT: %{{.+}} = cir.call @f10(%[[A]]) side_effect(pure) : (!s32i) -> !s32i
122 // CIR-NEXT: %[[B:.+]] = cir.const #cir.int<2> : !s32i
123 // CIR-NEXT: %{{.+}} = cir.call @f11(%[[B]]) side_effect(const) : (!s32i) -> !s32i
124
125 // LLVM-LABEL: define{{.*}} i32 @f12(){{.*}}
126 // LLVM: %{{.+}} = call i32 @f10(i32 1) #[[ATTR0:.+]]
127 // LLVM-NEXT: %{{.+}} = call i32 @f11(i32 2) #[[ATTR1:.+]]
128
129 // OGCG-LABEL: define{{.*}} i32 @f12()
130 // OGCG: %{{.+}} = call i32 @f10(i32 noundef 1) #[[ATTR0:.+]]
131 // OGCG-NEXT: %{{.+}} = call i32 @f11(i32 noundef 2) #[[ATTR1:.+]]
132
133 // LLVM: attributes #[[ATTR0]] = { nounwind willreturn memory(read) }
134 // LLVM: attributes #[[ATTR1]] = { nounwind willreturn memory(none) }
135
136 // OGCG: attributes #[[ATTR0]] = { nounwind willreturn memory(read) }
137 // OGCG: attributes #[[ATTR1]] = { nounwind willreturn memory(none) }