summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/strlenopt-36.c
blob: 56e59a431a49c668b9e9b3e97fbb709363c852c0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/* PR tree-optimization/78450 - strlen(s) return value can be assumed
   to be less than the size of s
   { dg-do compile }
   { dg-options "-O2 -fdump-tree-optimized" } */

#include "strlenopt.h"

extern char a7[7], a6[6], a5[5], a4[4], a3[3], a2[2], a1[1];
extern char a0[0];   /* Intentionally not tested here.  */
extern char ax[];    /* Same.  */

extern void failure_on_line (int);

#define TEST_FAIL(line)					\
  do {							\
    failure_on_line (line);				\
  } while (0)

#define T(expr)						\
  if (!(expr)) TEST_FAIL (__LINE__); else (void)0


void test_array (void)
{
  T (strlen (a7) < sizeof a7);
  T (strlen (a6) < sizeof a6);
  T (strlen (a5) < sizeof a5);
  T (strlen (a4) < sizeof a4);
  T (strlen (a3) < sizeof a3);

  /* The following two calls are folded too early which defeats
     the strlen() optimization.
    T (strlen (a2) == 1);
    T (strlen (a1) == 0);  */
}

/* { dg-final { scan-tree-dump-not "failure_on_line" "optimized" } } */