| 1 |
// PR tree-optimization/71625 - missing strlen optimization on different |
| 2 |
// array initialization style |
| 3 |
// |
| 4 |
// Verify that strlen() call with a constant character array argument |
| 5 |
// initialized with non-constant elements isn't folded. |
| 6 |
// |
| 7 |
// { dg-do compile } |
| 8 |
// { dg-options "-O2 -fdump-tree-optimized" } |
| 9 |
|
| 10 |
|
| 11 |
extern const char c; |
| 12 |
const char a0[] = { 'a', 'b', 'c', c }; |
| 13 |
|
| 14 |
int len0 () |
| 15 |
{ |
| 16 |
return __builtin_strlen (a0); |
| 17 |
} |
| 18 |
|
| 19 |
const char &ref = c; |
| 20 |
const char a1[] = { 'a', 'b', 'c', ref }; |
| 21 |
|
| 22 |
int len1 () |
| 23 |
{ |
| 24 |
return __builtin_strlen (a1); |
| 25 |
} |
| 26 |
|
| 27 |
const char* const ptr = &c; |
| 28 |
const char a2[] = { 'a', 'b', 'c', *ptr }; |
| 29 |
|
| 30 |
int len2 () |
| 31 |
{ |
| 32 |
return __builtin_strlen (a2); |
| 33 |
} |
| 34 |
|
| 35 |
// { dg-final { scan-tree-dump-times "strlen" 3 "optimized" } } |