modernc.org/ccgo/v3@v3.16.14/lib/testdata/gcc-9.1.0/gcc/testsuite/gcc.c-torture/execute/builtins/fprintf.c (about)

     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>
     9  extern int fprintf_unlocked (FILE *, const char *, ...);
    10  extern void abort(void);
    11  
    12  void
    13  main_test (void)
    14  {
    15    FILE *s_array[] = {stdout, NULL}, **s_ptr = s_array;
    16    const char *const s1 = "hello world";
    17    const char *const s2[] = { s1, 0 }, *const*s3;
    18    
    19    fprintf (*s_ptr, "");
    20    fprintf (*s_ptr, "%s", "");
    21    fprintf (*s_ptr, "%s", "hello");
    22    fprintf (*s_ptr, "%s", "\n");
    23    fprintf (*s_ptr, "%s", *s2);
    24    s3 = s2;
    25    fprintf (*s_ptr, "%s", *s3++);
    26    if (s3 != s2+1 || *s3 != 0)
    27      abort();
    28    s3 = s2;
    29    fprintf (*s_ptr++, "%s", *s3++);
    30    if (s3 != s2+1 || *s3 != 0 || s_ptr != s_array+1 || *s_ptr != 0)
    31      abort();
    32    
    33    s_ptr = s_array;
    34    fprintf (*s_ptr, "%c", '\n');
    35    fprintf (*s_ptr, "%c", **s2);
    36    s3 = s2;
    37    fprintf (*s_ptr, "%c", **s3++);
    38    if (s3 != s2+1 || *s3 != 0)
    39      abort();
    40    s3 = s2;
    41    fprintf (*s_ptr++, "%c", **s3++);
    42    if (s3 != s2+1 || *s3 != 0 || s_ptr != s_array+1 || *s_ptr != 0)
    43      abort();
    44    
    45    s_ptr = s_array;
    46    fprintf (*s_ptr++, "hello world");
    47    if (s_ptr != s_array+1 || *s_ptr != 0)
    48      abort();
    49    s_ptr = s_array;
    50    fprintf (*s_ptr, "\n");
    51      
    52    /* Test at least one instance of the __builtin_ style.  We do this
    53       to ensure that it works and that the prototype is correct.  */
    54    __builtin_fprintf (*s_ptr, "%s", "hello world\n");
    55    /* Check the unlocked style, these evaluate to nothing to avoid
    56       problems on systems without the unlocked functions.  */
    57    fprintf_unlocked (*s_ptr, "");
    58    __builtin_fprintf_unlocked (*s_ptr, "");
    59    fprintf_unlocked (*s_ptr, "%s", "");
    60    __builtin_fprintf_unlocked (*s_ptr, "%s", "");
    61  }