1 // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --function-signature
2 // RUN: %clang_cc1 -triple wasm32-unknown-unknown -o - -emit-llvm %s | FileCheck %s
6 // CHECK-LABEL: define {{[^@]+}}@test_i32
7 // CHECK-SAME: (ptr noundef [[FMT:%.*]], ...) #[[ATTR0:[0-9]+]] {
9 // CHECK-NEXT: [[FMT_ADDR:%.*]] = alloca ptr, align 4
10 // CHECK-NEXT: [[VA:%.*]] = alloca ptr, align 4
11 // CHECK-NEXT: [[V:%.*]] = alloca i32, align 4
12 // CHECK-NEXT: store ptr [[FMT]], ptr [[FMT_ADDR]], align 4
13 // CHECK-NEXT: call void @llvm.va_start.p0(ptr [[VA]])
14 // CHECK-NEXT: [[ARGP_CUR:%.*]] = load ptr, ptr [[VA]], align 4
15 // CHECK-NEXT: [[ARGP_NEXT:%.*]] = getelementptr inbounds i8, ptr [[ARGP_CUR]], i32 4
16 // CHECK-NEXT: store ptr [[ARGP_NEXT]], ptr [[VA]], align 4
17 // CHECK-NEXT: [[TMP0:%.*]] = load i32, ptr [[ARGP_CUR]], align 4
18 // CHECK-NEXT: store i32 [[TMP0]], ptr [[V]], align 4
19 // CHECK-NEXT: call void @llvm.va_end.p0(ptr [[VA]])
20 // CHECK-NEXT: [[TMP1:%.*]] = load i32, ptr [[V]], align 4
21 // CHECK-NEXT: ret i32 [[TMP1]]
23 int test_i32(char *fmt
, ...) {
27 int v
= va_arg(va
, int);
34 // CHECK-LABEL: define {{[^@]+}}@test_i64
35 // CHECK-SAME: (ptr noundef [[FMT:%.*]], ...) #[[ATTR0]] {
37 // CHECK-NEXT: [[FMT_ADDR:%.*]] = alloca ptr, align 4
38 // CHECK-NEXT: [[VA:%.*]] = alloca ptr, align 4
39 // CHECK-NEXT: [[V:%.*]] = alloca i64, align 8
40 // CHECK-NEXT: store ptr [[FMT]], ptr [[FMT_ADDR]], align 4
41 // CHECK-NEXT: call void @llvm.va_start.p0(ptr [[VA]])
42 // CHECK-NEXT: [[ARGP_CUR:%.*]] = load ptr, ptr [[VA]], align 4
43 // CHECK-NEXT: [[TMP0:%.*]] = getelementptr inbounds i8, ptr [[ARGP_CUR]], i32 7
44 // CHECK-NEXT: [[ARGP_CUR_ALIGNED:%.*]] = call ptr @llvm.ptrmask.p0.i32(ptr [[TMP0]], i32 -8)
45 // CHECK-NEXT: [[ARGP_NEXT:%.*]] = getelementptr inbounds i8, ptr [[ARGP_CUR_ALIGNED]], i32 8
46 // CHECK-NEXT: store ptr [[ARGP_NEXT]], ptr [[VA]], align 4
47 // CHECK-NEXT: [[TMP1:%.*]] = load i64, ptr [[ARGP_CUR_ALIGNED]], align 8
48 // CHECK-NEXT: store i64 [[TMP1]], ptr [[V]], align 8
49 // CHECK-NEXT: call void @llvm.va_end.p0(ptr [[VA]])
50 // CHECK-NEXT: [[TMP2:%.*]] = load i64, ptr [[V]], align 8
51 // CHECK-NEXT: ret i64 [[TMP2]]
53 long long test_i64(char *fmt
, ...) {
57 long long v
= va_arg(va
, long long);
70 // CHECK-LABEL: define {{[^@]+}}@test_struct
71 // CHECK-SAME: (ptr dead_on_unwind noalias writable sret([[STRUCT_S:%.*]]) align 4 [[AGG_RESULT:%.*]], ptr noundef [[FMT:%.*]], ...) #[[ATTR0]] {
73 // CHECK-NEXT: [[FMT_ADDR:%.*]] = alloca ptr, align 4
74 // CHECK-NEXT: [[VA:%.*]] = alloca ptr, align 4
75 // CHECK-NEXT: store ptr [[FMT]], ptr [[FMT_ADDR]], align 4
76 // CHECK-NEXT: call void @llvm.va_start.p0(ptr [[VA]])
77 // CHECK-NEXT: [[ARGP_CUR:%.*]] = load ptr, ptr [[VA]], align 4
78 // CHECK-NEXT: [[ARGP_NEXT:%.*]] = getelementptr inbounds i8, ptr [[ARGP_CUR]], i32 4
79 // CHECK-NEXT: store ptr [[ARGP_NEXT]], ptr [[VA]], align 4
80 // CHECK-NEXT: [[TMP0:%.*]] = load ptr, ptr [[ARGP_CUR]], align 4
81 // CHECK-NEXT: call void @llvm.memcpy.p0.p0.i32(ptr align 4 [[AGG_RESULT]], ptr align 4 [[TMP0]], i32 12, i1 false)
82 // CHECK-NEXT: call void @llvm.va_end.p0(ptr [[VA]])
83 // CHECK-NEXT: ret void
85 struct S
test_struct(char *fmt
, ...) {
89 struct S v
= va_arg(va
, struct S
);
98 // CHECK-LABEL: define {{[^@]+}}@test_empty_struct
99 // CHECK-SAME: (ptr dead_on_unwind noalias writable sret([[STRUCT_S:%.*]]) align 4 [[AGG_RESULT:%.*]], ptr noundef [[FMT:%.*]], ...) #[[ATTR0]] {
100 // CHECK-NEXT: entry:
101 // CHECK-NEXT: [[FMT_ADDR:%.*]] = alloca ptr, align 4
102 // CHECK-NEXT: [[VA:%.*]] = alloca ptr, align 4
103 // CHECK-NEXT: [[U:%.*]] = alloca [[STRUCT_Z:%.*]], align 1
104 // CHECK-NEXT: store ptr [[FMT]], ptr [[FMT_ADDR]], align 4
105 // CHECK-NEXT: call void @llvm.va_start.p0(ptr [[VA]])
106 // CHECK-NEXT: [[ARGP_CUR:%.*]] = load ptr, ptr [[VA]], align 4
107 // CHECK-NEXT: [[ARGP_NEXT:%.*]] = getelementptr inbounds i8, ptr [[ARGP_CUR]], i32 0
108 // CHECK-NEXT: store ptr [[ARGP_NEXT]], ptr [[VA]], align 4
109 // CHECK-NEXT: call void @llvm.memcpy.p0.p0.i32(ptr align 1 [[U]], ptr align 4 [[ARGP_CUR]], i32 0, i1 false)
110 // CHECK-NEXT: [[ARGP_CUR1:%.*]] = load ptr, ptr [[VA]], align 4
111 // CHECK-NEXT: [[ARGP_NEXT2:%.*]] = getelementptr inbounds i8, ptr [[ARGP_CUR1]], i32 4
112 // CHECK-NEXT: store ptr [[ARGP_NEXT2]], ptr [[VA]], align 4
113 // CHECK-NEXT: [[TMP0:%.*]] = load ptr, ptr [[ARGP_CUR1]], align 4
114 // CHECK-NEXT: call void @llvm.memcpy.p0.p0.i32(ptr align 4 [[AGG_RESULT]], ptr align 4 [[TMP0]], i32 12, i1 false)
115 // CHECK-NEXT: call void @llvm.va_end.p0(ptr [[VA]])
116 // CHECK-NEXT: ret void
118 struct S
test_empty_struct(char *fmt
, ...) {
122 struct Z u
= va_arg(va
, struct Z
);
123 struct S v
= va_arg(va
, struct S
);