On 08/26/18 05:34, Jeff Law wrote: > On 08/24/2018 01:52 PM, Bernd Edlinger wrote: >> Hi, >> >> this updated patch fixes one regression with current trunk due >> to a new test case. Sorry for the confusion. >> >> The change to the previous version is: >> 1) the check to avoid folding on empty char arrays is restored. >> 2) A null-termination character is added except when the string is full >> length. >> >> >> Bootstrapped and reg-tested on x86_64-pc-linux-gnu. >> Is it OK for trunk? >> >> >> Thanks >> Bernd. >> >> >> patch-bracedstr-v2.diff >> >> >> c-family: >> 2018-08-24 Bernd Edlinger <bernd.edlin...@hotmail.de> >> >> * c-common.c (braced_list_to_string): Remove eval parameter. >> Add some more checks. Always create zero-terminated STRING_CST. >> * c-common.h (braced_list_to_string): Adjust prototype. >> >> c: >> 2018-08-24 Bernd Edlinger <bernd.edlin...@hotmail.de> >> >> * c-decl.c (finish_decl): Call braced_list_to_string here ... >> * c-parser.c (c_parser_declaration_or_fndef): ... instead of here. >> >> >> cp: >> 2018-08-24 Bernd Edlinger <bernd.edlin...@hotmail.de> >> >> * decl.c (eval_check_narrowing): Remove. >> (check_initializer): Move call to braced_list_to_string from here ... >> * typeck2.c (store_init_value): ... to here. >> (digest_init_r): Remove handing of signed/unsigned char strings. >> >> testsuite: >> 2018-08-24 Bernd Edlinger <bernd.edlin...@hotmail.de> >> >> * c-c++-common/array-init.c: New test. >> * g++.dg/init/string2.C: Remove xfail. > My concern here is that you removed code that was explicitly added > during the initial review work of the patch that turned braced > initializers into strings. >
Yes, you mean BRACE_ENCLOSED_INITIALIZER_P which is (TREE_CODE (NODE) == CONSTRUCTOR && TREE_TYPE (NODE) == init_list_type_node) I tried that first but the TREE_TYPE of the CONSTRUCTOR was no longer init_list_type_node at that point. I think the middle-end needs the structure type here, and digest_init must have fixed that. This did not break in the debugger: + if (TREE_CODE (type) == ARRAY_TYPE + && TREE_CODE (value) == CONSTRUCTOR) + { + tree typ1 = TYPE_MAIN_VARIANT (TREE_TYPE (type)); + if (typ1 == char_type_node + || typ1 == signed_char_type_node + || typ1 == unsigned_char_type_node) + { + if (BRACE_ENCLOSED_INITIALIZER_P(value)) + asm("int3"); + value = braced_list_to_string (type, value); + } + } + while this + if (!BRACE_ENCLOSED_INITIALIZER_P(value)) + printf("%p - %p\n", TREE_TYPE(value), init_list_type_node); does this: $ cat test.cc char x[] = {1,2,3}; $ ../gcc-build/gcc/xgcc -B ../gcc-build/gcc/ -S test.cc 0x7fdedb821b28 - 0x7fdedb81f738 while the string is folded as expected. > >> - a[] = { 1, 2, 333, 0 }; // { dg-warning >> "\\\[\(-Wnarrowing|-Woverflow\)" "" { target { ! c++98_only } } } >> + a[] = { 1, 2, 333, 0 }; // { dg-warning >> "\\\[\(-Wnarrowing|-Woverflow\)" } > This is not an XFAIL, this is a selector. Essentially it says that the > diagnostic is appropriate when not in c++98 mode. > > You can see that to be the case if you compile the test in c++98 mode > without your change. It will compile with no errors or warnings. > > However, after your change it issues a warning for the narrowing > conversion in c++98 mode, which AFAICT it should not do. > This just restores the state _before_ Martin's braced initializer patch. So I have the impression that is actually a regression due to the original braced initializer patch. It is unfortunate that Martin did not check that. Bernd.