1 /* { dg-do run } */
2 /* { dg-options "-O2 -fdump-rtl-expand" } */
3 
4 typedef struct { char s[8]; int x; } S;
5 __attribute__ ((noinline)) int
f1(S * s)6 f1 (S * s)
7 {
8   int result = 0;
9   result += __builtin_strncmp (s->s, "ab", 2);
10   result += __builtin_strncmp (s->s, "abc", 3);
11   return result;
12 }
13 
14 __attribute__ ((noinline)) int
f2(char * p)15 f2 (char *p)
16 {
17   int result = 0;
18   result += __builtin_strncmp (p, "ab", 2);
19   result += __builtin_strncmp (p, "abc", 3);
20   return result;
21 }
22 
23 __attribute__ ((noinline)) int
f3(S * s)24 f3 (S * s)
25 {
26   int result = 0;
27   result += __builtin_strcmp (s->s, "a");
28   result += __builtin_strcmp (s->s, "ab");
29   return result;
30 }
31 
32 __attribute__ ((noinline)) int
f4(char * p)33 f4 (char *p)
34 {
35   int result = 0;
36   result += __builtin_strcmp (p, "a");
37   result += __builtin_strcmp (p, "ab");
38   return result;
39 }
40 
41 __attribute__ ((noinline)) int
f5(S * s)42 f5 (S * s)
43 {
44   int result = 0;
45   result += __builtin_memcmp (s->s, "ab", 2);
46   result += __builtin_memcmp (s->s, "abc", 3);
47   return result;
48 }
49 
50 __attribute__ ((noinline)) int
f6(char * p)51 f6 (char *p)
52 {
53   int result = 0;
54   result += __builtin_memcmp (p, "ab", 2);
55   result += __builtin_memcmp (p, "abc", 3);
56   return result;
57 }
58 
main(void)59 int main (void)
60 {
61   S ss = {{'a','b','c'}, 2};
62   char *s = "abcd";
63 
64   if (f1 (&ss) != 0 || f2 (s) != 0)
65     __builtin_abort ();
66 
67   if (f3 (&ss) <= 0 || f4 (s) <= 0)
68     __builtin_abort ();
69 
70   if (f5 (&ss) != 0 || f6 (s) != 0)
71     __builtin_abort ();
72 
73   return 0;
74 
75 }
76 
77 
78 /* { dg-final { scan-rtl-dump-times "__builtin_strcmp" 0 "expand" } } */
79 /* { dg-final { scan-rtl-dump-times "__builtin_strncmp" 0 "expand" } } */
80 /* { dg-final { scan-rtl-dump-times "__builtin_memcmp" 0 "expand" } } */
81