On 11/03/2016 01:46 PM, Richard Biener wrote: > On Thu, Nov 3, 2016 at 1:12 PM, Martin Liška <mli...@suse.cz> wrote: >> Hello. >> >> This is small follow-up of the patches I sent to string folding. >> The patch transforms character array defined in an initializer to string >> constant: >> >> +const char global[] = {'a', 'b', 'c', 'd', '\0'}; >> >> Apart from that, it also enables string folding of local symbols like: >> + const char local[] = "abcd"; >> >> Patch can bootstrap on ppc64le-redhat-linux and survives regression tests. > > Hmm, does this handle > > const char global[] = {'a', [4] = 'd', 'b', [3] = '\0'}; > > correctly?
It hasn't, fixed in the v2. As ctor indices are sorted in increasing order, I only check that there are no holes. > > I think you need to check that 'key' is increasing and there are no gaps > (ISTR constructor elements are sorted but gaps can still appear). > > + || !useless_type_conversion_p (TREE_TYPE (value), char_type_node)) > > please instead check the element type of the array constructor. I'd also > use a stricter check like TYPE_MAIN_VARIANT (type) == char_type_node > to avoid changing non-strings like unsigned / signed char. Ok, v2 does: TYPE_MAIN_VARIANT (type) == char_type_node > > Finally I'm a bit worried about doing this for all 'char' > constructors. Maybe we > should restrict this to those with ISPRINT () entries? Also done for all characters except the trailing \0 character. I'll send patch in the next email. Martin > > Richard. > > >> Martin