|
| 1 | +// RUN: %clang_cc1 -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 -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 | +// CIR: !rec___va_list_tag = !cir.record<struct "__va_list_tag" {!u32i, !u32i, !cir.ptr<!void>, !cir.ptr<!void>} |
| 9 | +// LLVM: %struct.__va_list_tag = type { i32, i32, ptr, ptr } |
| 10 | +// OGCG: %struct.__va_list_tag = type { i32, i32, ptr, ptr } |
| 11 | + |
| 12 | +void varargs(int count, ...) { |
| 13 | + __builtin_va_list args; |
| 14 | + __builtin_va_start(args, 12345); |
| 15 | + __builtin_va_end(args); |
| 16 | +} |
| 17 | + |
| 18 | +// CIR: cir.func dso_local @varargs(%[[COUNT:.+]]: !s32i{{.*}}, ...) |
| 19 | +// CIR: %[[COUNT_ADDR:.+]] = cir.alloca !s32i, !cir.ptr<!s32i>, ["count", init] |
| 20 | +// CIR: %[[ARGS:.+]] = cir.alloca !cir.array<!rec___va_list_tag x 1>, !cir.ptr<!cir.array<!rec___va_list_tag x 1>>, ["args"] |
| 21 | +// CIR: cir.store %[[COUNT]], %[[COUNT_ADDR]] : !s32i, !cir.ptr<!s32i> |
| 22 | +// CIR: %[[APTR:.+]] = cir.cast(array_to_ptrdecay, %[[ARGS]] : !cir.ptr<!cir.array<!rec___va_list_tag x 1>>), !cir.ptr<!rec___va_list_tag> |
| 23 | +// CIR: %[[C12345:.+]] = cir.const #cir.int<12345> : !s32i |
| 24 | +// CIR: cir.va_start %[[APTR]] %[[C12345]] : !cir.ptr<!rec___va_list_tag>, !s32i |
| 25 | +// CIR: %[[APTR2:.+]] = cir.cast(array_to_ptrdecay, %[[ARGS]] : !cir.ptr<!cir.array<!rec___va_list_tag x 1>>), !cir.ptr<!rec___va_list_tag> |
| 26 | +// CIR: cir.va_end %[[APTR2]] : !cir.ptr<!rec___va_list_tag> |
| 27 | +// CIR: cir.return |
| 28 | + |
| 29 | +// LLVM: define dso_local void @varargs( |
| 30 | +// LLVM: %[[ARGS:.+]] = alloca [1 x %struct.__va_list_tag], i64 1, align 16 |
| 31 | +// LLVM: %[[ARGS_PTR:.+]] = getelementptr %struct.__va_list_tag, ptr %[[ARGS]], i32 0 |
| 32 | +// LLVM: call void @llvm.va_start.p0(ptr %[[ARGS_PTR]]) |
| 33 | +// LLVM: %[[ARGS_PTR2:.+]] = getelementptr %struct.__va_list_tag, ptr %[[ARGS]], i32 0 |
| 34 | +// LLVM: call void @llvm.va_end.p0(ptr %[[ARGS_PTR2]]) |
| 35 | +// LLVM: ret void |
| 36 | + |
| 37 | +// OGCG: define dso_local void @varargs( |
| 38 | +// OGCG: %[[ARGS:.+]] = alloca [1 x %struct.__va_list_tag], align 16 |
| 39 | +// OGCG: %[[ARGS_PTR:.+]] = getelementptr inbounds [1 x %struct.__va_list_tag], ptr %[[ARGS]], i64 0, i64 0 |
| 40 | +// OGCG: call void @llvm.va_start.p0(ptr %[[ARGS_PTR]]) |
| 41 | +// OGCG: %[[ARGS_PTR2:.+]] = getelementptr inbounds [1 x %struct.__va_list_tag], ptr %[[ARGS]], i64 0, i64 0 |
| 42 | +// OGCG: call void @llvm.va_end.p0(ptr %[[ARGS_PTR2]]) |
| 43 | +// OGCG: ret void |
| 44 | + |
| 45 | +void stdarg_start(int count, ...) { |
| 46 | + __builtin_va_list args; |
| 47 | + __builtin_stdarg_start(args, 12345); |
| 48 | + __builtin_va_end(args); |
| 49 | +} |
| 50 | + |
| 51 | +// CIR: cir.func dso_local @stdarg_start(%[[COUNT2:.+]]: !s32i{{.*}}, ...) |
| 52 | +// CIR: %[[COUNT2_ADDR:.+]] = cir.alloca !s32i, !cir.ptr<!s32i>, ["count", init] |
| 53 | +// CIR: %[[ARGS2:.+]] = cir.alloca !cir.array<!rec___va_list_tag x 1>, !cir.ptr<!cir.array<!rec___va_list_tag x 1>>, ["args"] |
| 54 | +// CIR: cir.store %[[COUNT2]], %[[COUNT2_ADDR]] : !s32i, !cir.ptr<!s32i> |
| 55 | +// CIR: %[[APTR3:.+]] = cir.cast(array_to_ptrdecay, %[[ARGS2]] : !cir.ptr<!cir.array<!rec___va_list_tag x 1>>), !cir.ptr<!rec___va_list_tag> |
| 56 | +// CIR: %[[C12345_2:.+]] = cir.const #cir.int<12345> : !s32i |
| 57 | +// CIR: cir.va_start %[[APTR3]] %[[C12345_2]] : !cir.ptr<!rec___va_list_tag>, !s32i |
| 58 | +// CIR: %[[APTR4:.+]] = cir.cast(array_to_ptrdecay, %[[ARGS2]] : !cir.ptr<!cir.array<!rec___va_list_tag x 1>>), !cir.ptr<!rec___va_list_tag> |
| 59 | +// CIR: cir.va_end %[[APTR4]] : !cir.ptr<!rec___va_list_tag> |
| 60 | +// CIR: cir.return |
| 61 | + |
| 62 | +// LLVM: define dso_local void @stdarg_start( |
| 63 | +// LLVM: %[[ARGS:.+]] = alloca [1 x %struct.__va_list_tag], i64 1, align 16 |
| 64 | +// LLVM: %[[ARGS_PTR:.+]] = getelementptr %struct.__va_list_tag, ptr %[[ARGS]], i32 0 |
| 65 | +// LLVM: call void @llvm.va_start.p0(ptr %[[ARGS_PTR]]) |
| 66 | +// LLVM: %[[ARGS_PTR2:.+]] = getelementptr %struct.__va_list_tag, ptr %[[ARGS]], i32 0 |
| 67 | +// LLVM: call void @llvm.va_end.p0(ptr %[[ARGS_PTR2]]) |
| 68 | +// LLVM: ret void |
| 69 | + |
| 70 | +// OGCG: define dso_local void @stdarg_start( |
| 71 | +// OGCG: %[[ARGS:.+]] = alloca [1 x %struct.__va_list_tag], align 16 |
| 72 | +// OGCG: %[[ARGS_PTR:.+]] = getelementptr inbounds [1 x %struct.__va_list_tag], ptr %[[ARGS]], i64 0, i64 0 |
| 73 | +// OGCG: call void @llvm.va_start.p0(ptr %[[ARGS_PTR]]) |
| 74 | +// OGCG: %[[ARGS_PTR2:.+]] = getelementptr inbounds [1 x %struct.__va_list_tag], ptr %[[ARGS]], i64 0, i64 0 |
| 75 | +// OGCG: call void @llvm.va_end.p0(ptr %[[ARGS_PTR2]]) |
| 76 | +// OGCG: ret void |
0 commit comments