(root)/
gcc-13.2.0/
gcc/
testsuite/
gcc.dg/
strlenopt-28.c
       1  /* { dg-do run } */
       2  /* { dg-options "-O2 -fdump-tree-strlen" } */
       3  
       4  #include "strlenopt.h"
       5  
       6  volatile int v;
       7  
       8  size_t
       9  f1 (void)
      10  {
      11    char a[30];
      12    v += 1;
      13    memcpy (a, "1234567", 8);
      14    memcpy (a + 7, "89abcdefg", 10);
      15    memcpy (a + 16, "h", 2);
      16    return strlen (a);	// This strlen should be optimized into 17.
      17  }
      18  
      19  size_t
      20  f2 (void)
      21  {
      22    char a[30];
      23    v += 2;
      24    strcpy (a, "1234567");
      25    strcpy (a + 7, "89abcdefg");
      26    strcpy (a + 16, "h");
      27    return strlen (a);	// This strlen should be optimized into 17.
      28  }
      29  
      30  size_t
      31  f3 (char *a)
      32  {
      33    v += 3;
      34    memcpy (a, "1234567", 8);
      35    memcpy (a + 7, "89abcdefg", 10);
      36    memcpy (a + 16, "h", 2);
      37    return strlen (a);	// This strlen should be optimized into 17.
      38  }
      39  
      40  size_t
      41  f4 (char *a)
      42  {
      43    v += 4;
      44    strcpy (a, "1234567");
      45    strcpy (a + 7, "89abcdefg");
      46    strcpy (a + 16, "h");
      47    return strlen (a);	// This strlen should be optimized into 17.
      48  }
      49  
      50  int
      51  main ()
      52  {
      53    char a[30];
      54    if (f1 () != 17 || f2 () != 17 || f3 (a) != 17 || f4 (a) != 17)
      55      abort ();
      56    return 0;
      57  }
      58  
      59  /* { dg-final { scan-tree-dump-times "strlen \\(" 0 "strlen1" } } */