xref: /llvm-project/compiler-rt/test/BlocksRuntime/varargs.c (revision 2946cd701067404b99c39fb29dc9c74bd7193eb3)
1 //
2 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
3 // See https://llvm.org/LICENSE.txt for license information.
4 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5 
6 //  -*- mode:C; c-basic-offset:4; tab-width:4; intent-tabs-mode:nil;  -*-
7 // CONFIG
8 
9 #import <stdio.h>
10 #import <stdlib.h>
11 #import <string.h>
12 #import <stdarg.h>
13 
14 
main(int argc,const char * argv[])15 int main (int argc, const char * argv[]) {
16     int (^sumn)(int n, ...) = ^(int n, ...){
17         int result = 0;
18         va_list numbers;
19         int i;
20 
21         va_start(numbers, n);
22         for (i = 0 ; i < n ; i++) {
23             result += va_arg(numbers, int);
24         }
25         va_end(numbers);
26 
27         return result;
28     };
29     int six = sumn(3, 1, 2, 3);
30 
31     if ( six != 6 ) {
32         printf("%s: Expected 6 but got %d\n", argv[0], six);
33         exit(1);
34     }
35 
36     printf("%s: success\n", argv[0]);
37     return 0;
38 }
39