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 8 9 #include "stdarg.h" 10 11 int int_accumulator = 0; 12 double double_accumulator = 0; 13 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; 21 } 22 23 ch = *fmt++; 24 switch (ch) { 25 case 'd': 26 int_accumulator += va_arg(ap, int); 27 result++; 28 break; 29 30 case 'f': 31 double_accumulator += va_arg(ap, double); 32 result++; 33 break; 34 35 default: 36 break; 37 } 38 39 if (ch == '0') { 40 break; 41 } 42 } 43 return result; 44 } 45 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; 52 } 53