[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / CodeGen / X86 / x86_64-vaarg.c
blob450dfe5d15020324ae12e8049d7c9b6580e4bb57
1 // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --version 4
2 // RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm -o - %s | FileCheck %s
5 typedef struct { struct {} a; } empty;
7 // CHECK-LABEL: define dso_local void @empty_record_test(
8 // CHECK-SAME: i32 noundef [[Z:%.*]], ...) #[[ATTR0:[0-9]+]] {
9 // CHECK-NEXT: entry:
10 // CHECK-NEXT: [[Z_ADDR:%.*]] = alloca i32, align 4
11 // CHECK-NEXT: [[LIST:%.*]] = alloca [1 x %struct.__va_list_tag], align 16
12 // CHECK-NEXT: store i32 [[Z]], ptr [[Z_ADDR]], align 4
13 // CHECK-NEXT: [[ARRAYDECAY:%.*]] = getelementptr inbounds [1 x %struct.__va_list_tag], ptr [[LIST]], i64 0, i64 0
14 // CHECK-NEXT: call void @llvm.va_start.p0(ptr [[ARRAYDECAY]])
15 // CHECK-NEXT: [[ARRAYDECAY1:%.*]] = getelementptr inbounds [1 x %struct.__va_list_tag], ptr [[LIST]], i64 0, i64 0
16 // CHECK-NEXT: ret void
18 empty empty_record_test(int z, ...) {
19 __builtin_va_list list;
20 __builtin_va_start(list, z);
21 return __builtin_va_arg(list, empty);
24 typedef struct {
25 struct{} a;
26 double b;
27 } s1;
29 // CHECK-LABEL: define dso_local double @f(
30 // CHECK-SAME: i32 noundef [[Z:%.*]], ...) #[[ATTR0]] {
31 // CHECK-NEXT: entry:
32 // CHECK-NEXT: [[RETVAL:%.*]] = alloca [[STRUCT_S1:%.*]], align 8
33 // CHECK-NEXT: [[Z_ADDR:%.*]] = alloca i32, align 4
34 // CHECK-NEXT: [[LIST:%.*]] = alloca [1 x %struct.__va_list_tag], align 16
35 // CHECK-NEXT: store i32 [[Z]], ptr [[Z_ADDR]], align 4
36 // CHECK-NEXT: [[ARRAYDECAY:%.*]] = getelementptr inbounds [1 x %struct.__va_list_tag], ptr [[LIST]], i64 0, i64 0
37 // CHECK-NEXT: call void @llvm.va_start.p0(ptr [[ARRAYDECAY]])
38 // CHECK-NEXT: [[ARRAYDECAY1:%.*]] = getelementptr inbounds [1 x %struct.__va_list_tag], ptr [[LIST]], i64 0, i64 0
39 // CHECK-NEXT: [[FP_OFFSET_P:%.*]] = getelementptr inbounds nuw [[STRUCT___VA_LIST_TAG:%.*]], ptr [[ARRAYDECAY1]], i32 0, i32 1
40 // CHECK-NEXT: [[FP_OFFSET:%.*]] = load i32, ptr [[FP_OFFSET_P]], align 4
41 // CHECK-NEXT: [[FITS_IN_FP:%.*]] = icmp ule i32 [[FP_OFFSET]], 160
42 // CHECK-NEXT: br i1 [[FITS_IN_FP]], label [[VAARG_IN_REG:%.*]], label [[VAARG_IN_MEM:%.*]]
43 // CHECK: vaarg.in_reg:
44 // CHECK-NEXT: [[TMP0:%.*]] = getelementptr inbounds nuw [[STRUCT___VA_LIST_TAG]], ptr [[ARRAYDECAY1]], i32 0, i32 3
45 // CHECK-NEXT: [[REG_SAVE_AREA:%.*]] = load ptr, ptr [[TMP0]], align 16
46 // CHECK-NEXT: [[TMP1:%.*]] = getelementptr i8, ptr [[REG_SAVE_AREA]], i32 [[FP_OFFSET]]
47 // CHECK-NEXT: [[TMP2:%.*]] = add i32 [[FP_OFFSET]], 16
48 // CHECK-NEXT: store i32 [[TMP2]], ptr [[FP_OFFSET_P]], align 4
49 // CHECK-NEXT: br label [[VAARG_END:%.*]]
50 // CHECK: vaarg.in_mem:
51 // CHECK-NEXT: [[OVERFLOW_ARG_AREA_P:%.*]] = getelementptr inbounds nuw [[STRUCT___VA_LIST_TAG]], ptr [[ARRAYDECAY1]], i32 0, i32 2
52 // CHECK-NEXT: [[OVERFLOW_ARG_AREA:%.*]] = load ptr, ptr [[OVERFLOW_ARG_AREA_P]], align 8
53 // CHECK-NEXT: [[OVERFLOW_ARG_AREA_NEXT:%.*]] = getelementptr i8, ptr [[OVERFLOW_ARG_AREA]], i32 8
54 // CHECK-NEXT: store ptr [[OVERFLOW_ARG_AREA_NEXT]], ptr [[OVERFLOW_ARG_AREA_P]], align 8
55 // CHECK-NEXT: br label [[VAARG_END]]
56 // CHECK: vaarg.end:
57 // CHECK-NEXT: [[VAARG_ADDR:%.*]] = phi ptr [ [[TMP1]], [[VAARG_IN_REG]] ], [ [[OVERFLOW_ARG_AREA]], [[VAARG_IN_MEM]] ]
58 // CHECK-NEXT: call void @llvm.memcpy.p0.p0.i64(ptr align 8 [[RETVAL]], ptr align 8 [[VAARG_ADDR]], i64 8, i1 false)
59 // CHECK-NEXT: [[COERCE_DIVE:%.*]] = getelementptr inbounds nuw [[STRUCT_S1]], ptr [[RETVAL]], i32 0, i32 0
60 // CHECK-NEXT: [[TMP3:%.*]] = load double, ptr [[COERCE_DIVE]], align 8
61 // CHECK-NEXT: ret double [[TMP3]]
63 s1 f(int z, ...) {
64 __builtin_va_list list;
65 __builtin_va_start(list, z);
66 return __builtin_va_arg(list, s1);