Home | History | Annotate | Download | only in CodeGenCXX
      1 // RUN: %clang_cc1 -Wno-non-pod-varargs -emit-llvm %s -o - -triple=i686-pc-win32 -mconstructor-aliases -fno-rtti | FileCheck %s
      2 
      3 #include <stdarg.h>
      4 
      5 struct A {
      6   A(int a) : a(a) {}
      7   A(const A &o) : a(o.a) {}
      8   ~A() {}
      9   int a;
     10 };
     11 
     12 int foo(A a, ...) {
     13   va_list ap;
     14   va_start(ap, a);
     15   int sum = 0;
     16   for (int i = 0; i < a.a; ++i)
     17     sum += va_arg(ap, int);
     18   va_end(ap);
     19   return sum;
     20 }
     21 
     22 // CHECK-LABEL: define i32 @"\01?foo@@YAHUA@@ZZ"(<{ %struct.A }>* inalloca, ...)
     23 
     24 int main() {
     25   return foo(A(3), 1, 2, 3);
     26 }
     27 // CHECK-LABEL: define i32 @main()
     28 // CHECK: %[[argmem:[^ ]*]] = alloca inalloca <{ %struct.A, i32, i32, i32 }>
     29 // CHECK: call i32 {{.*bitcast.*}}@"\01?foo@@YAHUA@@ZZ"{{.*}}(<{ %struct.A, i32, i32, i32 }>* inalloca %[[argmem]])
     30 
     31 void varargs_zero(...);
     32 void varargs_one(int, ...);
     33 void varargs_two(int, int, ...);
     34 void varargs_three(int, int, int, ...);
     35 void call_var_args() {
     36   A x(3);
     37   varargs_zero(x);
     38   varargs_one(1, x);
     39   varargs_two(1, 2, x);
     40   varargs_three(1, 2, 3, x);
     41 }
     42 
     43 // CHECK-LABEL: define void @"\01?call_var_args@@YAXXZ"()
     44 // CHECK: call void {{.*bitcast.*varargs_zero.*}}(<{ %struct.A }>* inalloca %{{.*}})
     45 // CHECK: call void {{.*bitcast.*varargs_one.*}}(<{ i32, %struct.A }>* inalloca %{{.*}})
     46 // CHECK: call void {{.*bitcast.*varargs_two.*}}(<{ i32, i32, %struct.A }>* inalloca %{{.*}})
     47 // CHECK: call void {{.*bitcast.*varargs_three.*}}(<{ i32, i32, i32, %struct.A }>* inalloca %{{.*}})
     48 
     49 // CHECK-LABEL: declare void @"\01?varargs_zero@@YAXZZ"(...)
     50 // CHECK-LABEL: declare void @"\01?varargs_one@@YAXHZZ"(i32, ...)
     51 // CHECK-LABEL: declare void @"\01?varargs_two@@YAXHHZZ"(i32, i32, ...)
     52 // CHECK-LABEL: declare void @"\01?varargs_three@@YAXHHHZZ"(i32, i32, i32, ...)
     53