File: strlenopt-30.c

package info (click to toggle)
gcc-riscv64-unknown-elf 8.3.0.2019.08%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 680,956 kB
  • sloc: ansic: 3,237,715; cpp: 896,882; ada: 772,854; f90: 144,254; asm: 68,788; makefile: 67,456; sh: 29,743; exp: 28,045; objc: 15,273; fortran: 11,885; python: 7,369; pascal: 5,375; awk: 3,725; perl: 2,872; yacc: 316; xml: 311; ml: 285; lex: 198; haskell: 122
file content (63 lines) | stat: -rw-r--r-- 1,123 bytes parent folder | download | duplicates (4)
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 "strlen" } } */