diff options
author | Martin Sebor <msebor@redhat.com> | 2018-08-13 17:57:51 +0000 |
---|---|---|
committer | Martin Sebor <msebor@gcc.gnu.org> | 2018-08-13 11:57:51 -0600 |
commit | 23aa9f7c4637ad51587e536e245ae6adb5391bbc (patch) | |
tree | f8eac004f5eeb0fa8a2376e0ab0e5fb0844532e2 /gcc/c | |
parent | e6a1e5fe7346458208ede97741382061a6191024 (diff) | |
download | gcc-23aa9f7c4637ad51587e536e245ae6adb5391bbc.zip gcc-23aa9f7c4637ad51587e536e245ae6adb5391bbc.tar.gz gcc-23aa9f7c4637ad51587e536e245ae6adb5391bbc.tar.bz2 |
PR tree-optimization/71625 - missing strlen optimization on different array initialization style
gcc/c/ChangeLog:
PR tree-optimization/71625
* c-parser.c (c_parser_declaration_or_fndef): Call
braced_list_to_string.
gcc/c-family/ChangeLog:
PR tree-optimization/71625
* c-common.c (braced_list_to_string): New function.
* c-common.h (braced_list_to_string): Declare it.
gcc/cp/ChangeLog:
PR tree-optimization/71625
* decl.c (check_initializer): Call braced_list_to_string.
(eval_check_narrowing): New function.
* gcc/cp/typeck2.c (digest_init_r): Accept strings literals
as initilizers for all narrow character types.
gcc/testsuite/ChangeLog:
PR tree-optimization/71625
* g++.dg/init/string2.C: New test.
* g++.dg/init/string3.C: New test.
* g++.dg/init/string4.C: New test.
* gcc.dg/init-string-3.c: New test.
* gcc.dg/strlenopt-55.c: New test.
* gcc.dg/strlenopt-56.c: New test.
From-SVN: r263511
Diffstat (limited to 'gcc/c')
-rw-r--r-- | gcc/c/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/c/c-parser.c | 9 |
2 files changed, 15 insertions, 0 deletions
diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog index 40e56f3..be2ffbd 100644 --- a/gcc/c/ChangeLog +++ b/gcc/c/ChangeLog @@ -1,3 +1,9 @@ +2018-08-13 Martin Sebor <msebor@redhat.com> + + PR tree-optimization/71625 + * c-parser.c (c_parser_declaration_or_fndef): Call + braced_list_to_string. + 2018-08-03 Bogdan Harjoc <harjoc@gmail.com> PR c/86690 diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser.c index 7a92628..5ad4f57 100644 --- a/gcc/c/c-parser.c +++ b/gcc/c/c-parser.c @@ -2126,6 +2126,15 @@ c_parser_declaration_or_fndef (c_parser *parser, bool fndef_ok, if (d != error_mark_node) { maybe_warn_string_init (init_loc, TREE_TYPE (d), init); + + /* Try to convert a string CONSTRUCTOR into a STRING_CST. */ + tree valtype = TREE_TYPE (init.value); + if (TREE_CODE (init.value) == CONSTRUCTOR + && TREE_CODE (valtype) == ARRAY_TYPE + && TYPE_STRING_FLAG (TREE_TYPE (valtype))) + if (tree str = braced_list_to_string (valtype, init.value)) + init.value = str; + finish_decl (d, init_loc, init.value, init.original_type, asm_name); } |