blob: 2ba1ee05700faf160bf3888f550f006ee0b1068f (
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
|
/* PR tree-optimization/83821 - local aggregate initialization defeats
strlen optimization
Verify that a strlen() call is eliminated for a pointer to a region
of memory allocated by calloc() even if one or more nul bytes are
written into it.
{ dg-do compile }
{ dg-options "-O2 -fno-tree-vectorize -fdump-tree-optimized" } */
unsigned n0, n1;
void* elim_strlen_calloc_store_memset_1 (unsigned a, unsigned b)
{
char *p = __builtin_calloc (a, 1);
p[0] = '\0';
p[1] = '\0';
p[2] = '\0';
p[3] = '\0';
__builtin_memset (p, 0, b);
n0 = __builtin_strlen (p);
return p;
}
void* elim_strlen_calloc_store_memset_2 (unsigned a, unsigned b, unsigned c)
{
char *p = __builtin_calloc (a, 1);
p[1] = '\0';
__builtin_memset (p, 0, b);
n0 = __builtin_strlen (p);
p[3] = 0;
__builtin_memset (p, 0, c);
n1 = __builtin_strlen (p);
return p;
}
/* { dg-final { scan-tree-dump-not "__builtin_strlen" "optimized" } } */
|