On 08/08/18 19:33, Bernd Edlinger wrote: > Hi Martin, > > sorry, I hope you forgive me, when I add a few comments to your patch. > >> + unsigned HOST_WIDE_INT nelts = CONSTRUCTOR_NELTS (ctor); >> + tree eltype = TREE_TYPE (type); > ... >> + /* Bail if the CTOR has a block of more than 256 embedded nuls >> + due to implicitly initialized elements. */ >> + unsigned nelts = (idx - str.length ()) + 1; >> + if (nelts > 256) >> + return NULL_TREE; > > nelts shadows previous nelts. > >> + if (!nelts || str.length () < i) > > I don't understand when is str.length () < i ? > >> + /* Append a nul for the empty initializer { } and for the last >> + explicit initializer in the loop above that is a nul. */ >> + str.safe_push (0); >> + >> + /* Build a string literal but return the embedded STRING_CST. */ >> + tree res = build_string_literal (str.length (), str.begin ()); >> + res = TREE_OPERAND (TREE_OPERAND (res, 0), 0); >> + return res; >> +} > > > res has a different type than the object you initialize. > I think you should use: > > tree res = build_string (str.length (), str.begin ()); > TREE_TYPE (res) = type; > return res; >
Sorry, again, but could it be possible that this test case changed with your patch? $ cat w.c const char x[] = { }; int main() { __builtin_printf("%ld\n", sizeof(x)); return 0; } $ gcc w.c $ ./a.out 1 without your patch $ ./a.out 0 Bernd.