Mercurial > hg > CbC > CbC_gcc
comparison gcc/testsuite/gcc.dg/strlenopt-86.c @ 145:1830386684a0
gcc-9.2.0
author | anatofuz |
---|---|
date | Thu, 13 Feb 2020 11:34:05 +0900 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
131:84e7813d76e9 | 145:1830386684a0 |
---|---|
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" } */ | |
8 | |
9 unsigned n0, n1; | |
10 | |
11 void* | |
12 keep_strlen_calloc_store_cst_memset (int i, unsigned a, unsigned b) | |
13 { | |
14 char *p = __builtin_calloc (a, 1); | |
15 | |
16 p[i] = 'x'; | |
17 | |
18 __builtin_memset (p, 0, b); | |
19 | |
20 n0 = __builtin_strlen (p); | |
21 | |
22 return p; | |
23 } | |
24 | |
25 void* | |
26 keep_strlen_calloc_store_var_memset (int i, int x, unsigned a, unsigned b) | |
27 { | |
28 char *p = __builtin_calloc (a, 1); | |
29 | |
30 p[i] = x; | |
31 | |
32 __builtin_memset (p, 0, b); | |
33 | |
34 n0 = __builtin_strlen (p); | |
35 | |
36 return p; | |
37 } | |
38 | |
39 void* | |
40 keep_strlen_calloc_store_memset_2 (int i, int x, unsigned a, unsigned b, unsigned c) | |
41 { | |
42 char *p = __builtin_calloc (a, 1); | |
43 | |
44 p[i] = x; | |
45 __builtin_memset (p, 0, b); | |
46 | |
47 n0 = __builtin_strlen (p); | |
48 | |
49 p[3] = x; | |
50 __builtin_memset (p, 0, c); | |
51 | |
52 n1 = __builtin_strlen (p); | |
53 | |
54 return p; | |
55 } | |
56 | |
57 /* { dg-final { scan-tree-dump-times "__builtin_strlen" 4 "optimized" } } */ |