libcpp, c, middle-end: Optimize initializers using #embed in C
[official-gcc.git] / gcc / testsuite / gcc.dg / strlenopt-86.c
blobd2029443556843d51b5be585927e9fdf9f128834
1 /* PR tree-optimization/83821 - local aggregate initialization defeats
2 strlen optimization
3 Verify that a strlen() call is not eliminated for a pointer to a region
4 of memory allocated by calloc() if a byte is written into the region
5 that isn't known to be nul.
6 { dg-do compile }
7 { dg-options "-O2 -fdump-tree-optimized" } */
9 unsigned n0, n1;
11 void*
12 keep_strlen_calloc_store_cst_memset (int i, unsigned a, unsigned b)
14 char *p = __builtin_calloc (a, 1);
16 p[i] = 'x';
18 __builtin_memset (p, 0, b);
20 n0 = __builtin_strlen (p);
22 return p;
25 void*
26 keep_strlen_calloc_store_var_memset (int i, int x, unsigned a, unsigned b)
28 char *p = __builtin_calloc (a, 1);
30 p[i] = x;
32 __builtin_memset (p, 0, b);
34 n0 = __builtin_strlen (p);
36 return p;
39 void*
40 keep_strlen_calloc_store_memset_2 (int i, int x, unsigned a, unsigned b, unsigned c)
42 char *p = __builtin_calloc (a, 1);
44 p[i] = x;
45 __builtin_memset (p, 0, b);
47 n0 = __builtin_strlen (p);
49 p[3] = x;
50 __builtin_memset (p, 0, c);
52 n1 = __builtin_strlen (p);
54 return p;
57 /* { dg-final { scan-tree-dump-times "__builtin_strlen" 4 "optimized" } } */