(root)/
gcc-13.2.0/
gcc/
testsuite/
gcc.c-torture/
execute/
builtins/
strlen-3.c
       1  /* Copyright (C) 2004  Free Software Foundation.
       2  
       3     Test strlen on const variables initialized to string literals.
       4  
       5     Written by Jakub Jelinek, 9/14/2004.  */
       6  
       7  extern void abort (void);
       8  extern __SIZE_TYPE__ strlen (const char *);
       9  extern char *strcpy (char *, const char *);
      10  static const char bar[] = "Hello, World!";
      11  static const char baz[] = "hello, world?";
      12  static const char larger[20] = "short string";
      13  extern int inside_main;
      14  
      15  int l1 = 1;
      16  int x = 6;
      17  
      18  void
      19  main_test(void)
      20  {
      21    inside_main = 1;
      22  
      23  #ifdef __OPTIMIZE__
      24    const char *foo;
      25    int i;
      26  #endif
      27  
      28    if (strlen (bar) != 13)
      29      abort ();
      30  
      31    if (strlen (bar + 3) != 10)
      32      abort ();
      33  
      34    if (strlen (&bar[6]) != 7)
      35      abort ();
      36  
      37    if (strlen (bar + (x++ & 7)) != 7)
      38      abort ();
      39    if (x != 7)
      40      abort ();
      41  
      42  #ifdef __OPTIMIZE__
      43    foo = bar;
      44    for (i = 0; i < 4; ++i)
      45      {
      46        if (i == l1 - 1)
      47  	foo = "HELLO, WORLD!";
      48        else if (i == l1)
      49  	foo = bar;
      50        else if (i == l1 + 1)
      51  	foo = "hello, world!";
      52        else
      53  	foo = baz;
      54      }
      55    if (strlen (foo) != 13)
      56      abort ();
      57  #endif
      58  
      59    if (strlen (larger) != 12)
      60      abort ();
      61    if (strlen (&larger[10]) != 2)
      62      abort ();
      63  
      64    inside_main = 0;
      65    /* The following call may or may not be folded depending on
      66       the optimization level, and when it isn't folded (such
      67       as may be the case with -Og) it may or may not result in
      68       a library call, depending on whether or not it's expanded
      69       inline (e.g., powerpc64 makes a call while x86_64 expands
      70       it inline).  */
      71    if (strlen (larger + (x++ & 7)) != 5)
      72      abort ();
      73    if (x != 8)
      74      abort ();
      75    inside_main = 1;
      76  }