public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/91544] When initializing allocatable character array get "Error: size of variable 'A.0' is too large"
       [not found] <bug-91544-4@http.gcc.gnu.org/bugzilla/>
@ 2022-05-09 17:38 ` burnus at gcc dot gnu.org
  0 siblings, 0 replies; only message in thread
From: burnus at gcc dot gnu.org @ 2022-05-09 17:38 UTC (permalink / raw)
  To: gcc-bugs

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>));

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-05-09 17:38 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-91544-4@http.gcc.gnu.org/bugzilla/>
2022-05-09 17:38 ` [Bug fortran/91544] When initializing allocatable character array get "Error: size of variable 'A.0' is too large" burnus at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).