1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 %s -ffreestanding 2*f4a2713aSLionel Sambuc // RUN: %clang_cc1 %s -ffreestanding -triple i686-unknown-linux 3*f4a2713aSLionel Sambuc // RUN: %clang_cc1 %s -ffreestanding -triple x86_64-unknown-linux 4*f4a2713aSLionel Sambuc // RUN: %clang_cc1 %s -ffreestanding -triple mips-unknown-linux 5*f4a2713aSLionel Sambuc // RUN: %clang_cc1 %s -ffreestanding -triple mipsel-unknown-linux 6*f4a2713aSLionel Sambuc // RUN: %clang_cc1 %s -ffreestanding -triple armv7-unknown-linux-gnueabi 7*f4a2713aSLionel Sambuc // RUN: %clang_cc1 %s -ffreestanding -triple thumbv7-unknown-linux-gnueabi 8*f4a2713aSLionel Sambuc 9*f4a2713aSLionel Sambuc #include "stdarg.h" 10*f4a2713aSLionel Sambuc 11*f4a2713aSLionel Sambuc int int_accumulator = 0; 12*f4a2713aSLionel Sambuc double double_accumulator = 0; 13*f4a2713aSLionel Sambuc test_vprintf(const char * fmt,va_list ap)14*f4a2713aSLionel Sambucint test_vprintf(const char *fmt, va_list ap) { 15*f4a2713aSLionel Sambuc char ch; 16*f4a2713aSLionel Sambuc int result = 0; 17*f4a2713aSLionel Sambuc while (*fmt != '\0') { 18*f4a2713aSLionel Sambuc ch = *fmt++; 19*f4a2713aSLionel Sambuc if (ch != '%') { 20*f4a2713aSLionel Sambuc continue; 21*f4a2713aSLionel Sambuc } 22*f4a2713aSLionel Sambuc 23*f4a2713aSLionel Sambuc ch = *fmt++; 24*f4a2713aSLionel Sambuc switch (ch) { 25*f4a2713aSLionel Sambuc case 'd': 26*f4a2713aSLionel Sambuc int_accumulator += va_arg(ap, int); 27*f4a2713aSLionel Sambuc result++; 28*f4a2713aSLionel Sambuc break; 29*f4a2713aSLionel Sambuc 30*f4a2713aSLionel Sambuc case 'f': 31*f4a2713aSLionel Sambuc double_accumulator += va_arg(ap, double); 32*f4a2713aSLionel Sambuc result++; 33*f4a2713aSLionel Sambuc break; 34*f4a2713aSLionel Sambuc 35*f4a2713aSLionel Sambuc default: 36*f4a2713aSLionel Sambuc break; 37*f4a2713aSLionel Sambuc } 38*f4a2713aSLionel Sambuc 39*f4a2713aSLionel Sambuc if (ch == '0') { 40*f4a2713aSLionel Sambuc break; 41*f4a2713aSLionel Sambuc } 42*f4a2713aSLionel Sambuc } 43*f4a2713aSLionel Sambuc return result; 44*f4a2713aSLionel Sambuc } 45*f4a2713aSLionel Sambuc test_printf(const char * fmt,...)46*f4a2713aSLionel Sambucint test_printf(const char *fmt, ...) { 47*f4a2713aSLionel Sambuc va_list ap; 48*f4a2713aSLionel Sambuc va_start(ap, fmt); 49*f4a2713aSLionel Sambuc int result = test_vprintf(fmt, ap); 50*f4a2713aSLionel Sambuc va_end(ap); 51*f4a2713aSLionel Sambuc return result; 52*f4a2713aSLionel Sambuc } 53