https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91544
Tobias Burnus <burnus at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |burnus at gcc dot gnu.org --- Comment #2 from Tobias Burnus <burnus at gcc dot gnu.org> --- Reconfirmed with GCC 13. Internally, the following code is generated (for my example, -fdump-tree-original): static character(kind=1) A.0[3][1:D.4246] = {"abcde", "fhji", "klmno"}; The problem is that D.4246 is a variable and not a constant. I think the proper solution is to create an array for max length, i.e. 5 in this example with right padding if too short: static character(kind=1) A.0[3][1:5] = {"abcde", "fhji ", "klmno"}; And then in the array use, there is already some code like the following. However, here, not only the .x (= desired length) but also the actual length (here: 5) has to be taken into account for the memmove/memset bit, i.e. min(.x, 5). (In the example below, .x, D.4251 and D.4252 are all the same - and match either the LHS after allocation or RHS of the assignment.) .x = i >= -2 ? (integer(kind=8)) (i + 2) : 0; ... D.4252 = .x; D.4253 = (void *) D.4242 + (sizetype) (((S.1 + D.4249) + D.4243) * x.span); D.4254 = (void *) &A.0[S.1]; if (D.4252 > 0) { if (NON_LVALUE_EXPR <D.4251> < NON_LVALUE_EXPR <D.4252>) { __builtin_memmove (D.4253, D.4254, (unsigned long) NON_LVALUE_EXPR <D.4251>); __builtin_memset (D.4253 + (sizetype) NON_LVALUE_EXPR <D.4251>, 32, (unsigned long) (NON_LVALUE_EXPR <D.4252> - NON_LVALUE_EXPR <D.4251>));