]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/testsuite/gcc.dg/tree-ssa/calloc-5.c
PR tree-optimization/83821 - local aggregate initialization defeats strlen optimization
[thirdparty/gcc.git] / gcc / testsuite / gcc.dg / tree-ssa / calloc-5.c
1 /* PR tree-optimization/83821 - local aggregate initialization defeats
2 strlen optimization
3 Verify that with DSE disabled, a memset() call to zero out a subregion
4 of memory allocated by calloc() is not eliminated after a non-zero byte
5 is written into it using memset() in between the two calls.
6 { dg-do compile }
7 { dg-options "-O2 -fno-tree-dse -fdump-tree-optimized" } */
8
9 char* keep_memset_calls (void)
10 {
11 char *p = __builtin_calloc (12, 1);
12
13 __builtin_memset (p + 5, 1, 2); /* dead store (not eliminated) */
14
15 __builtin_memset (p, 0, 12); /* must not be eliminated */
16
17 return p;
18 }
19
20 /* { dg-final { scan-tree-dump-not "malloc" "optimized" } }
21 { dg-final { scan-tree-dump-times "_calloc \\\(" 1 "optimized" } }
22 { dg-final { scan-tree-dump-times "_memset \\\(" 2 "optimized" } } */