[docs] Add LICENSE.txt to the root of the mono-repo
[llvm-project.git] / clang / test / SemaCXX / builtins-va_arg.cpp
blob4f549c8db6f0de11474cce0f2227b731e2da0811
1 // RUN: %clang_cc1 %s -ffreestanding
2 // RUN: %clang_cc1 %s -ffreestanding -triple i686-unknown-linux
3 // RUN: %clang_cc1 %s -ffreestanding -triple x86_64-unknown-linux
4 // RUN: %clang_cc1 %s -ffreestanding -triple mips-unknown-linux
5 // RUN: %clang_cc1 %s -ffreestanding -triple mipsel-unknown-linux
6 // RUN: %clang_cc1 %s -ffreestanding -triple armv7-unknown-linux-gnueabi
7 // RUN: %clang_cc1 %s -ffreestanding -triple thumbv7-unknown-linux-gnueabi
9 #include "stdarg.h"
11 int int_accumulator = 0;
12 double double_accumulator = 0;
14 int test_vprintf(const char *fmt, va_list ap) {
15 char ch;
16 int result = 0;
17 while (*fmt != '\0') {
18 ch = *fmt++;
19 if (ch != '%') {
20 continue;
23 ch = *fmt++;
24 switch (ch) {
25 case 'd':
26 int_accumulator += va_arg(ap, int);
27 result++;
28 break;
30 case 'f':
31 double_accumulator += va_arg(ap, double);
32 result++;
33 break;
35 default:
36 break;
39 if (ch == '0') {
40 break;
43 return result;
46 int test_printf(const char *fmt, ...) {
47 va_list ap;
48 va_start(ap, fmt);
49 int result = test_vprintf(fmt, ap);
50 va_end(ap);
51 return result;