| 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 |
|
| 6 |
void f1() {} |
| 7 |
void f2() { |
| 8 |
f1(); |
| 9 |
} |
| 10 |
|
| 11 |
// CIR-LABEL: cir.func{{.*}} @_Z2f1v |
| 12 |
// CIR-LABEL: cir.func{{.*}} @_Z2f2v |
| 13 |
// CIR: cir.call @_Z2f1v() : () -> () |
| 14 |
|
| 15 |
// LLVM-LABEL: define{{.*}} void @_Z2f2v(){{.*}} { |
| 16 |
// LLVM: call void @_Z2f1v() |
| 17 |
|
| 18 |
int f3() { return 2; } |
| 19 |
int f4() { |
| 20 |
int x = f3(); |
| 21 |
return x; |
| 22 |
} |
| 23 |
|
| 24 |
// CIR-LABEL: cir.func{{.*}} @_Z2f3v() -> !s32i |
| 25 |
// CIR-LABEL: cir.func{{.*}} @_Z2f4v() -> !s32i |
| 26 |
// CIR: cir.call @_Z2f3v() : () -> !s32i |
| 27 |
|
| 28 |
// LLVM-LABEL: define{{.*}} i32 @_Z2f4v(){{.*}} { |
| 29 |
// LLVM: %{{.+}} = call i32 @_Z2f3v() |
| 30 |
|
| 31 |
int f5(int a, int *b, bool c); |
| 32 |
int f6() { |
| 33 |
int b = 1; |
| 34 |
return f5(2, &b, false); |
| 35 |
} |
| 36 |
|
| 37 |
// CIR-LABEL: cir.func{{.*}} @_Z2f6v() -> !s32i |
| 38 |
// CIR: %[[#b:]] = cir.alloca !s32i, !cir.ptr<!s32i>, ["b", init] |
| 39 |
// CIR: %[[#a:]] = cir.const #cir.int<2> : !s32i |
| 40 |
// CIR-NEXT: %[[#c:]] = cir.const #false |
| 41 |
// CIR-NEXT: %{{.+}} = cir.call @_Z2f5iPib(%[[#a]], %[[#b:]], %[[#c]]) : (!s32i, !cir.ptr<!s32i>, !cir.bool) -> !s32i |
| 42 |
|
| 43 |
// LLVM-LABEL: define{{.*}} i32 @_Z2f6v(){{.*}} { |
| 44 |
// LLVM: %{{.+}} = call i32 @_Z2f5iPib(i32 2, ptr %{{.+}}, i1 false) |
| 45 |
|
| 46 |
int f7(int (*ptr)(int, int)) { |
| 47 |
return ptr(1, 2); |
| 48 |
} |
| 49 |
|
| 50 |
// CIR-LABEL: cir.func{{.*}} @_Z2f7PFiiiE |
| 51 |
// CIR: %[[#ptr:]] = cir.load{{.*}} %{{.+}} : !cir.ptr<!cir.ptr<!cir.func<(!s32i, !s32i) -> !s32i>>>, !cir.ptr<!cir.func<(!s32i, !s32i) -> !s32i>> |
| 52 |
// CIR-NEXT: %[[#a:]] = cir.const #cir.int<1> : !s32i |
| 53 |
// CIR-NEXT: %[[#b:]] = cir.const #cir.int<2> : !s32i |
| 54 |
// CIR-NEXT: %{{.+}} = cir.call %[[#ptr]](%[[#a]], %[[#b]]) : (!cir.ptr<!cir.func<(!s32i, !s32i) -> !s32i>>, !s32i, !s32i) -> !s32i |
| 55 |
|
| 56 |
// LLVM-LABEL: define{{.*}} i32 @_Z2f7PFiiiE |
| 57 |
// LLVM: %[[#ptr:]] = load ptr, ptr %{{.+}} |
| 58 |
// LLVM-NEXT: %{{.+}} = call i32 %[[#ptr]](i32 1, i32 2) |
| 59 |
|
| 60 |
void f8(int a, ...); |
| 61 |
void f9() { |
| 62 |
f8(1); |
| 63 |
f8(1, 2, 3, 4); |
| 64 |
} |
| 65 |
|
| 66 |
// CIR-LABEL: cir.func{{.*}} @_Z2f9v() |
| 67 |
// CIR: cir.call @_Z2f8iz(%{{.+}}) : (!s32i) -> () |
| 68 |
// CIR: cir.call @_Z2f8iz(%{{.+}}, %{{.+}}, %{{.+}}, %{{.+}}) : (!s32i, !s32i, !s32i, !s32i) -> () |
| 69 |
|
| 70 |
// LLVM-LABEL: define{{.*}} void @_Z2f9v(){{.*}} |
| 71 |
// LLVM: call void (i32, ...) @_Z2f8iz(i32 1) |
| 72 |
// LLVM: call void (i32, ...) @_Z2f8iz(i32 1, i32 2, i32 3, i32 4) |
| 73 |
|
| 74 |
struct S { |
| 75 |
int x; |
| 76 |
int y; |
| 77 |
}; |
| 78 |
|
| 79 |
S f10(); |
| 80 |
void f11() { |
| 81 |
S s = f10(); |
| 82 |
} |
| 83 |
|
| 84 |
// CIR-LABEL: cir.func{{.*}} @_Z3f11v() |
| 85 |
// CIR: %[[#s:]] = cir.call @_Z3f10v() : () -> !rec_S |
| 86 |
// CIR-NEXT: cir.store align(4) %[[#s]], %{{.+}} : !rec_S, !cir.ptr<!rec_S> |
| 87 |
|
| 88 |
// LLVM-LABEL: define{{.*}} void @_Z3f11v(){{.*}} |
| 89 |
// LLVM: %[[#s:]] = call %struct.S @_Z3f10v() |
| 90 |
// LLVM-NEXT: store %struct.S %[[#s]], ptr %{{.+}}, align 4 |
| 91 |
|
| 92 |
void f12() { |
| 93 |
f10(); |
| 94 |
} |
| 95 |
|
| 96 |
// CIR-LABEL: cir.func{{.*}} @_Z3f12v() |
| 97 |
// CIR: %[[#slot:]] = cir.alloca !rec_S, !cir.ptr<!rec_S>, ["agg.tmp0"] |
| 98 |
// CIR-NEXT: %[[#ret:]] = cir.call @_Z3f10v() : () -> !rec_S |
| 99 |
// CIR-NEXT: cir.store align(4) %[[#ret]], %[[#slot]] : !rec_S, !cir.ptr<!rec_S> |
| 100 |
|
| 101 |
// LLVM-LABEL: define{{.*}} void @_Z3f12v(){{.*}} { |
| 102 |
// LLVM: %[[#slot:]] = alloca %struct.S, i64 1, align 4 |
| 103 |
// LLVM-NEXT: %[[#ret:]] = call %struct.S @_Z3f10v() |
| 104 |
// LLVM-NEXT: store %struct.S %[[#ret]], ptr %[[#slot]], align 4 |
| 105 |
|
| 106 |
void f13() noexcept; |
| 107 |
void f14() { |
| 108 |
f13(); |
| 109 |
} |
| 110 |
|
| 111 |
// CIR-LABEL: cir.func{{.+}} @_Z3f14v() |
| 112 |
// CIR: cir.call @_Z3f13v() nothrow : () -> () |
| 113 |
// CIR: } |
| 114 |
|
| 115 |
// LLVM-LABEL: define{{.+}} void @_Z3f14v(){{.*}} |
| 116 |
// LLVM: call void @_Z3f13v() #[[LLVM_ATTR_0:.+]] |
| 117 |
// LLVM: } |
| 118 |
|
| 119 |
int f15(); |
| 120 |
void f16() { |
| 121 |
using T = int; |
| 122 |
f15().~T(); |
| 123 |
} |
| 124 |
|
| 125 |
// CIR-LABEL: @_Z3f16v |
| 126 |
// CIR-NEXT: %{{.+}} = cir.call @_Z3f15v() : () -> !s32i |
| 127 |
// CIR: } |
| 128 |
|
| 129 |
// LLVM-LABEL: define{{.+}} void @_Z3f16v(){{.*}} { |
| 130 |
// LLVM-NEXT: %{{.+}} = call i32 @_Z3f15v() |
| 131 |
// LLVM: } |
| 132 |
|
| 133 |
// LLVM: attributes #[[LLVM_ATTR_0]] = { nounwind } |