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

     1  /* Copyright (C) 2000, 2003  Free Software Foundation.
     2  
     3     Ensure all expected transformations of builtin strstr occur and
     4     perform correctly in presence of redirect.  */
     5  
     6  #define ASMNAME(cname)  ASMNAME2 (__USER_LABEL_PREFIX__, cname)
     7  #define ASMNAME2(prefix, cname) STRING (prefix) cname
     8  #define STRING(x)    #x
     9  
    10  typedef __SIZE_TYPE__ size_t;
    11  extern void abort (void);
    12  extern char *strstr (const char *, const char *)
    13    __asm (ASMNAME ("my_strstr"));
    14  
    15  const char *p = "rld", *q = "hello world";
    16  
    17  void
    18  main_test (void)
    19  {
    20    const char *const foo = "hello world";
    21  
    22    if (strstr (foo, "") != foo)
    23      abort ();
    24    if (strstr (foo + 4, "") != foo + 4)
    25      abort ();
    26    if (strstr (foo, "h") != foo)
    27      abort ();
    28    if (strstr (foo, "w") != foo + 6)
    29      abort ();
    30    if (strstr (foo + 6, "o") != foo + 7)
    31      abort ();
    32    if (strstr (foo + 1, "world") != foo + 6)
    33      abort ();
    34    if (strstr (foo + 2, p) != foo + 8)
    35      abort ();
    36    if (strstr (q, "") != q)
    37      abort ();
    38    if (strstr (q + 1, "o") != q + 4)
    39      abort ();
    40  
    41    /* Test at least one instance of the __builtin_ style.  We do this
    42       to ensure that it works and that the prototype is correct.  */
    43    if (__builtin_strstr (foo + 1, "world") != foo + 6)
    44      abort ();
    45  }