1/* Copyright (C) 2001 Free Software Foundation. 2 3 Ensure all expected transformations of builtin fprintf occur and 4 that we honor side effects in the arguments. 5 6 Written by Kaveh R. Ghazi, 1/7/2001. */ 7 8#include <stdio.h> 9extern int fprintf (FILE *, const char *, ...); 10extern void abort(void); 11 12int main() 13{ 14 FILE *s_array[] = {stdout, NULL}, **s_ptr = s_array; 15 const char *const s1 = "hello world"; 16 const char *const s2[] = { s1, 0 }, *const*s3; 17 18 fprintf (*s_ptr, "%s", "hello"); 19 fprintf (*s_ptr, "%s", "\n"); 20 fprintf (*s_ptr, "%s", *s2); 21 s3 = s2; 22 fprintf (*s_ptr, "%s", *s3++); 23 if (s3 != s2+1 || *s3 != 0) 24 abort(); 25 s3 = s2; 26 fprintf (*s_ptr++, "%s", *s3++); 27 if (s3 != s2+1 || *s3 != 0 || s_ptr != s_array+1 || *s_ptr != 0) 28 abort(); 29 30 s_ptr = s_array; 31 fprintf (*s_ptr, "%c", '\n'); 32 fprintf (*s_ptr, "%c", **s2); 33 s3 = s2; 34 fprintf (*s_ptr, "%c", **s3++); 35 if (s3 != s2+1 || *s3 != 0) 36 abort(); 37 s3 = s2; 38 fprintf (*s_ptr++, "%c", **s3++); 39 if (s3 != s2+1 || *s3 != 0 || s_ptr != s_array+1 || *s_ptr != 0) 40 abort(); 41 42 s_ptr = s_array; 43 fprintf (*s_ptr++, "hello world"); 44 if (s_ptr != s_array+1 || *s_ptr != 0) 45 abort(); 46 s_ptr = s_array; 47 fprintf (*s_ptr, "\n"); 48 49 /* Test at least one instance of the __builtin_ style. We do this 50 to ensure that it works and that the prototype is correct. */ 51 __builtin_fprintf (*s_ptr, "%s", "hello world\n"); 52 53 return 0; 54} 55 56#ifdef __OPTIMIZE__ 57/* When optimizing, all the above cases should be transformed into 58 something else. So any remaining calls to the original function 59 should abort. */ 60static int 61fprintf (FILE *stream, const char *string, ...) 62{ 63 abort(); 64} 65#endif 66