(root)/
gcc-13.2.0/
gcc/
testsuite/
gcc.dg/
strlenopt-32.c
       1  /* { dg-do run } */
       2  /* { dg-options "-O2 -fdump-tree-strlen" } */
       3  
       4  #include "strlenopt.h"
       5  
       6  char temp[30];
       7  volatile int v;
       8  
       9  size_t __attribute__ ((noinline, noclone))
      10  f1 (void)
      11  {
      12    char a[30];
      13    v += 1;
      14    memcpy (a, "1234567", 7);
      15    memcpy (a + 7, "89abcdefg", 9);
      16    memcpy (a + 16, "h", 2);
      17    return strlen (a);	// This strlen should be optimized into 17.
      18  }
      19  
      20  size_t __attribute__ ((noinline, noclone))
      21  f2 (char *a)
      22  {
      23    v += 2;
      24    memcpy (a, "1234567", 7);
      25    memcpy (a + 7, "89abcdefg", 9);
      26    memcpy (a + 16, "h", 2);
      27    return strlen (a);	// This strlen should be optimized into 17.
      28  }
      29  
      30  size_t __attribute__ ((noinline, noclone))
      31  f3 (void)
      32  {
      33    char a[30];
      34    v += 3;
      35    a[0] = '1';
      36    memcpy (a + 1, "2345678", 8);
      37    return strlen (a);	// This strlen should be optimized into 8.
      38  }
      39  
      40  size_t __attribute__ ((noinline, noclone))
      41  f4 (char *a)
      42  {
      43    v += 4;
      44    a[0] = '1';
      45    memcpy (a + 1, "2345678", 8);
      46    return strlen (a);	// This strlen should be optimized into 8.
      47  }
      48  
      49  size_t __attribute__ ((noinline, noclone))
      50  f5 (void)
      51  {
      52    char a[30];
      53    v += 5;
      54    a[0] = '1';
      55    a[1] = '2';
      56    a[2] = '3';
      57    memcpy (a + 3, "456", 3);
      58    a[6] = '7';
      59    a[7] = 0;
      60    return strlen (a);	// This strlen should be optimized into 7.
      61  }
      62  
      63  size_t __attribute__ ((noinline, noclone))
      64  f6 (char *a)
      65  {
      66    v += 6;
      67    a[0] = '1';
      68    a[1] = '2';
      69    a[2] = '3';
      70    memcpy (a + 3, "456", 3);
      71    a[6] = '7';
      72    a[7] = 0;
      73    return strlen (a);	// This strlen should be optimized into 7.
      74  }
      75  
      76  size_t __attribute__ ((noinline, noclone))
      77  f7 (void)
      78  {
      79    char a[30];
      80    v += 7;
      81    strcpy (a, "abcde");
      82    int len1 = strlen (a);
      83    a[2] = '_';
      84    int len2 = strlen (a);
      85    return len1 + len2;	// This should be optimized into 10.
      86  }
      87  
      88  size_t __attribute__ ((noinline, noclone))
      89  f8 (char *a)
      90  {
      91    v += 8;
      92    strcpy (a, "abcde");
      93    int len1 = strlen (a);
      94    a[2] = '_';
      95    int len2 = strlen (a);
      96    return len1 + len2;	// This should be optimized into 10.
      97  }
      98  
      99  size_t __attribute__ ((noinline, noclone))
     100  f9 (char b)
     101  {
     102    char a[30];
     103    v += 9;
     104    strcpy (a, "foo.bar");
     105    a[4] = b;
     106    a[3] = 0;
     107    return strlen (a);	// This should be optimized into 3.
     108  }
     109  
     110  size_t __attribute__ ((noinline, noclone))
     111  f10 (char *a, char b)
     112  {
     113    v += 10;
     114    strcpy (a, "foo.bar");
     115    a[4] = b;
     116    a[3] = 0;
     117    return strlen (a);	// This should be optimized into 3.
     118  }
     119  
     120  size_t __attribute__ ((noinline, noclone))
     121  f11 (void)
     122  {
     123    char a[30];
     124    v += 11;
     125    strcpy (temp, "123456");
     126    memcpy (a, temp, 7);
     127    return strlen (a);	// This should be optimized into 6.
     128  }
     129  
     130  size_t __attribute__ ((noinline, noclone))
     131  f12 (char *a)
     132  {
     133    v += 12;
     134    strcpy (temp, "123456");
     135    memcpy (a, temp, 7);
     136    return strlen (a);	// This should be optimized into 6.
     137  }
     138  
     139  size_t __attribute__ ((noinline, noclone))
     140  f13 (void)
     141  {
     142    char a[30];
     143    v += 13;
     144    strcpy (temp, "1234567");
     145    memcpy (a, temp, 7);
     146    a[7] = 0;
     147    return strlen (a);	// This should be optimized into 7.
     148  }
     149  
     150  size_t __attribute__ ((noinline, noclone))
     151  f14 (char *a)
     152  {
     153    v += 14;
     154    strcpy (temp, "1234567");
     155    memcpy (a, temp, 7);
     156    a[7] = 0;
     157    return strlen (a);	// This should be optimized into 7.
     158  }
     159  
     160  size_t __attribute__ ((noinline, noclone))
     161  f15 (void)
     162  {
     163    char a[30];
     164    v += 15;
     165    strcpy (temp, "12345679");
     166    memcpy (a, temp, 7);
     167    a[7] = 0;
     168    return strlen (a);	// This should be optimized into 7.
     169  }
     170  
     171  size_t __attribute__ ((noinline, noclone))
     172  f16 (char *a)
     173  {
     174    v += 16;
     175    strcpy (temp, "123456789");
     176    memcpy (a, temp, 7);
     177    a[7] = 0;
     178    return strlen (a);	// This should be optimized into 7.
     179  }
     180  
     181  int
     182  main ()
     183  {
     184    char a[30];
     185    if (f1 () != 17 || f2 (a) != 17 || f3 () != 8 || f4 (a) != 8
     186        || f5 () != 7 || f6 (a) != 7 || f7 () != 10 || f8 (a) != 10
     187        || f9 ('_') != 3 || f10 (a, '_') != 3 || f11 () != 6 || f12 (a) != 6
     188        || f13 () != 7 || f14 (a) != 7 || f15 () != 7 || f16 (a) != 7)
     189      abort ();
     190    return 0;
     191  }
     192  
     193  /* { dg-final { scan-tree-dump-times "strlen \\(" 0 "strlen1" } } */