summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/strlenopt-30.c
blob: 2a3098ba96f78641477703501711b4829340bdb0 (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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/* { dg-do compile } */
/* { dg-options "-O2 -fdump-tree-strlen" } */

__attribute__((no_icf))
_Bool f1(char *s)
{
  return __builtin_strstr (s, "hello") == s;
}

__attribute__((no_icf))
_Bool f2(char *s)
{
  return s == __builtin_strstr (s, "hello");
}

__attribute__((no_icf))
_Bool f3(char *s)
{
  return s != __builtin_strstr (s, "hello");
}

__attribute__((no_icf))
_Bool f4()
{
  char *foo_f4(void);
  char *t1 = foo_f4();
  char *t2 = __builtin_strstr (t1, "hello");
  _Bool t3 = t2 == t1;
  return t3;
}

__attribute__((no_icf))
void f5(char *s)
{
  char *t1 = __builtin_strstr (s, "hello");
  void foo_f5(void);
  if (t1 != s)
    foo_f5();
}

/* Do not perform transform, since strlen (t)
   is unknown.  */

__attribute__((no_icf))
_Bool f6(char *s, char *t)
{
  return __builtin_strstr (s, t) == s;
}

/* Do not perform transform in this case, since
   t1 doesn't have single use.  */

__attribute__((no_icf))
_Bool f7(char *s)
{
  void foo_f7(char *);

  char *t1 = __builtin_strstr (s, "hello");
  foo_f7 (t1);
  return (t1 == s);
}

/* { dg-final { scan-tree-dump-times "__builtin_strncmp" 5 "strlen1" } } */