2014-07-08 10:24:27 +08:00
|
|
|
// RUN: %clang_cc1 -Wno-non-pod-varargs -emit-llvm %s -o - -triple=i686-pc-win32 -mconstructor-aliases -fno-rtti | FileCheck %s
|
2014-02-01 08:04:45 +08:00
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
|
|
|
struct A {
|
|
|
|
A(int a) : a(a) {}
|
|
|
|
A(const A &o) : a(o.a) {}
|
|
|
|
~A() {}
|
|
|
|
int a;
|
|
|
|
};
|
|
|
|
|
|
|
|
int foo(A a, ...) {
|
|
|
|
va_list ap;
|
|
|
|
va_start(ap, a);
|
|
|
|
int sum = 0;
|
|
|
|
for (int i = 0; i < a.a; ++i)
|
|
|
|
sum += va_arg(ap, int);
|
|
|
|
va_end(ap);
|
|
|
|
return sum;
|
|
|
|
}
|
|
|
|
|
2022-01-16 17:53:11 +08:00
|
|
|
// CHECK-LABEL: define dso_local noundef i32 @"?foo@@YAHUA@@ZZ"(<{ %struct.A }>* inalloca(<{ %struct.A }>) %0, ...)
|
2014-07-08 10:24:27 +08:00
|
|
|
|
2014-02-01 08:04:45 +08:00
|
|
|
int main() {
|
|
|
|
return foo(A(3), 1, 2, 3);
|
|
|
|
}
|
2022-01-16 17:53:11 +08:00
|
|
|
// CHECK-LABEL: define dso_local noundef i32 @main()
|
2014-07-08 10:24:27 +08:00
|
|
|
// CHECK: %[[argmem:[^ ]*]] = alloca inalloca <{ %struct.A, i32, i32, i32 }>
|
2022-01-16 17:53:11 +08:00
|
|
|
// CHECK: call noundef i32 {{.*bitcast.*}}@"?foo@@YAHUA@@ZZ"{{.*}}(<{ %struct.A, i32, i32, i32 }>* inalloca(<{ %struct.A, i32, i32, i32 }>) %[[argmem]])
|
2014-07-08 10:24:27 +08:00
|
|
|
|
|
|
|
void varargs_zero(...);
|
|
|
|
void varargs_one(int, ...);
|
|
|
|
void varargs_two(int, int, ...);
|
|
|
|
void varargs_three(int, int, int, ...);
|
|
|
|
void call_var_args() {
|
|
|
|
A x(3);
|
|
|
|
varargs_zero(x);
|
|
|
|
varargs_one(1, x);
|
|
|
|
varargs_two(1, 2, x);
|
|
|
|
varargs_three(1, 2, 3, x);
|
|
|
|
}
|
|
|
|
|
2018-03-17 04:36:49 +08:00
|
|
|
// CHECK-LABEL: define dso_local void @"?call_var_args@@YAXXZ"()
|
2021-03-29 20:42:23 +08:00
|
|
|
// CHECK: call void {{.*bitcast.*varargs_zero.*}}(<{ %struct.A }>* inalloca(<{ %struct.A }>) %{{.*}})
|
|
|
|
// CHECK: call void {{.*bitcast.*varargs_one.*}}(<{ i32, %struct.A }>* inalloca(<{ i32, %struct.A }>) %{{.*}})
|
|
|
|
// CHECK: call void {{.*bitcast.*varargs_two.*}}(<{ i32, i32, %struct.A }>* inalloca(<{ i32, i32, %struct.A }>) %{{.*}})
|
|
|
|
// CHECK: call void {{.*bitcast.*varargs_three.*}}(<{ i32, i32, i32, %struct.A }>* inalloca(<{ i32, i32, i32, %struct.A }>) %{{.*}})
|
2014-07-08 10:24:27 +08:00
|
|
|
|
2018-03-17 04:36:49 +08:00
|
|
|
// CHECK-LABEL: declare dso_local void @"?varargs_zero@@YAXZZ"(...)
|
2022-01-16 17:53:11 +08:00
|
|
|
// CHECK-LABEL: declare dso_local void @"?varargs_one@@YAXHZZ"(i32 noundef, ...)
|
|
|
|
// CHECK-LABEL: declare dso_local void @"?varargs_two@@YAXHHZZ"(i32 noundef, i32 noundef, ...)
|
|
|
|
// CHECK-LABEL: declare dso_local void @"?varargs_three@@YAXHHHZZ"(i32 noundef, i32 noundef, i32 noundef, ...)
|