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
64
65
66
67
|
/* { dg-do run } */
/* { dg-options "-O2 -fdump-tree-strlen" } */
char s[100] = {'a','b','c','d'};
typedef struct { char s[8]; int x; } S;
__attribute__ ((noinline)) int
f1 (S *s)
{
return __builtin_strcmp (s->s, "abc") != 0;
}
__attribute__ ((noinline)) int
f2 (void)
{
return __builtin_strcmp (s, "abc") != 0;
}
__attribute__ ((noinline)) int
f3 (S *s)
{
return __builtin_strcmp ("abc", s->s) != 0;
}
__attribute__ ((noinline)) int
f4 (void)
{
return __builtin_strcmp ("abc", s) != 0;
}
__attribute__ ((noinline)) int
f5 (S *s)
{
return __builtin_strncmp (s->s, "abc", 3) != 0;
}
__attribute__ ((noinline)) int
f6 (void)
{
return __builtin_strncmp (s, "abc", 2) != 0;
}
__attribute__ ((noinline)) int
f7 (S *s)
{
return __builtin_strncmp ("abc", s->s, 3) != 0;
}
__attribute__ ((noinline)) int
f8 (void)
{
return __builtin_strncmp ("abc", s, 2) != 0;
}
int main (void)
{
S ss = {{'a','b','c'}, 2};
if (f1 (&ss) != 0 || f2 () != 1 || f3 (&ss) != 0 ||
f4 () != 1 || f5 (&ss) != 0 || f6 () != 0 ||
f7 (&ss) != 0 || f8 () != 0)
__builtin_abort ();
return 0;
}
/* { dg-final { scan-tree-dump-times "cmp_eq \\(" 8 "strlen" } } */
|