(root)/
gcc-13.2.0/
gcc/
testsuite/
gcc.dg/
strlenopt-36.c
       1  /* PR tree-optimization/78450 - strlen(s) return value can be assumed
       2     to be less than the size of s
       3     { dg-do compile }
       4     { dg-options "-O2 -fdump-tree-optimized" } */
       5  
       6  #include "strlenopt.h"
       7  
       8  extern char a7[7], a6[6], a5[5], a4[4], a3[3], a2[2], a1[1];
       9  extern char a0[0];   /* Intentionally not tested here.  */
      10  extern char ax[];    /* Same.  */
      11  
      12  extern void failure_on_line (int);
      13  
      14  #define TEST_FAIL(line)					\
      15    do {							\
      16      failure_on_line (line);				\
      17    } while (0)
      18  
      19  #define T(expr)						\
      20    if (!(expr)) TEST_FAIL (__LINE__); else (void)0
      21  
      22  
      23  void test_array (void)
      24  {
      25    T (strlen (a7) < sizeof a7);
      26    T (strlen (a6) < sizeof a6);
      27    T (strlen (a5) < sizeof a5);
      28    T (strlen (a4) < sizeof a4);
      29    T (strlen (a3) < sizeof a3);
      30  
      31    /* The following two calls are folded too early which defeats
      32       the strlen() optimization.
      33      T (strlen (a2) == 1);
      34      T (strlen (a1) == 0);  */
      35  }
      36  
      37  /* { dg-final { scan-tree-dump-not "failure_on_line" "optimized" } } */