]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/testsuite/gcc.dg/strcmpopt_2.c
Update copyright years.
[thirdparty/gcc.git] / gcc / testsuite / gcc.dg / strcmpopt_2.c
1 /* { dg-do run } */
2 /* { dg-options "-O2 -fdump-tree-strlen" } */
3
4 char s[100] = {'a','b','c','d'};
5 typedef struct { char s[8]; int x; } S;
6
7 __attribute__ ((noinline)) int
8 f1 (S *s)
9 {
10 /* Member arrays not handled due to the fix for PR 92765. */
11 return 0; // __builtin_strcmp (s->s, "abc") != 0;
12 }
13
14 __attribute__ ((noinline)) int
15 f2 (void)
16 {
17 return __builtin_strcmp (s, "abc") != 0;
18 }
19
20 __attribute__ ((noinline)) int
21 f3 (S *s)
22 {
23 return 0; // __builtin_strcmp ("abc", s->s) != 0;
24 }
25
26 __attribute__ ((noinline)) int
27 f4 (void)
28 {
29 return __builtin_strcmp ("abc", s) != 0;
30 }
31
32 __attribute__ ((noinline)) int
33 f5 (S *s)
34 {
35 return 0; // __builtin_strncmp (s->s, "abc", 3) != 0;
36 }
37
38 __attribute__ ((noinline)) int
39 f6 (void)
40 {
41 return __builtin_strncmp (s, "abc", 2) != 0;
42 }
43
44 __attribute__ ((noinline)) int
45 f7 (S *s)
46 {
47 return 0; // __builtin_strncmp ("abc", s->s, 3) != 0;
48 }
49
50 __attribute__ ((noinline)) int
51 f8 (void)
52 {
53 return __builtin_strncmp ("abc", s, 2) != 0;
54 }
55
56 int main (void)
57 {
58 S ss = {{'a','b','c'}, 2};
59
60 if (f1 (&ss) != 0 || f2 () != 1 || f3 (&ss) != 0 ||
61 f4 () != 1 || f5 (&ss) != 0 || f6 () != 0 ||
62 f7 (&ss) != 0 || f8 () != 0)
63 __builtin_abort ();
64
65 return 0;
66 }
67
68 /* { dg-final { scan-tree-dump-times "cmp_eq \\(" 4 "strlen1" } } */