Debian Codegraph @

clang/test/CIR/CodeGen/defaultarg.cpp

raw
1 // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir -std=c++17 %s -o %t.cir
2 // RUN: FileCheck %s --input-file=%t.cir --check-prefix=CIR
3 // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-llvm -std=c++17 %s -o %t-cir.ll
4 // RUN: FileCheck %s --input-file=%t-cir.ll --check-prefix=LLVM
5 // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm -std=c++17 %s -o %t.ll
6 // RUN: FileCheck %s --input-file=%t.ll --check-prefix=OGCG
7
8 void bar(const int &i = 42);
9
10 void foo() {
11 bar();
12 }
13
14 // CIR: cir.func {{.*}} @_Z3foov()
15 // CIR: cir.scope {
16 // CIR: %[[TMP0:.*]] = cir.alloca !s32i, !cir.ptr<!s32i>, ["ref.tmp0"]
17 // CIR: %[[TMP1:.*]] = cir.const #cir.int<42>
18 // CIR: cir.store{{.*}} %[[TMP1]], %[[TMP0]]
19 // CIR: cir.call @_Z3barRKi(%[[TMP0]])
20 // CIR: }
21
22 // LLVM: define{{.*}} @_Z3foov()
23 // LLVM: %[[TMP0:.*]] = alloca i32
24 // LLVM: br label %[[SCOPE_LABEL:.*]]
25 // LLVM: [[SCOPE_LABEL]]:
26 // LLVM: store i32 42, ptr %[[TMP0]]
27 // LLVM: call void @_Z3barRKi(ptr %[[TMP0]])
28
29 // OGCG: define{{.*}} @_Z3foov()
30 // OGCG: %[[TMP0:.*]] = alloca i32
31 // OGCG: store i32 42, ptr %[[TMP0]]
32 // OGCG: call void @_Z3barRKi(ptr {{.*}} %[[TMP0]])
33
34 struct S
35 {
36 S(int n = 2);
37 };
38
39 void test_ctor_defaultarg() {
40 S s;
41 }
42
43 // CIR: cir.func {{.*}} @_Z20test_ctor_defaultargv()
44 // CIR: %[[S:.*]] = cir.alloca !rec_S, !cir.ptr<!rec_S>, ["s", init]
45 // CIR: %[[TWO:.*]] = cir.const #cir.int<2> : !s32i
46 // CIR: cir.call @_ZN1SC1Ei(%[[S]], %[[TWO]]) : (!cir.ptr<!rec_S>, !s32i) -> ()
47
48 // LLVM: define{{.*}} @_Z20test_ctor_defaultargv()
49 // LLVM: %[[S:.*]] = alloca %struct.S
50 // LLVM: call void @_ZN1SC1Ei(ptr %[[S]], i32 2)
51
52 // OGCG: define{{.*}} @_Z20test_ctor_defaultargv()
53 // OGCG: %[[S:.*]] = alloca %struct.S
54 // OGCG: call void @_ZN1SC1Ei(ptr{{.*}} %[[S]], i32 {{.*}} 2)