From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id DD3F0385742A; Mon, 9 May 2022 17:38:16 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DD3F0385742A From: "burnus at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug fortran/91544] When initializing allocatable character array get "Error: size of variable 'A.0' is too large" Date: Mon, 09 May 2022 17:38:16 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: fortran X-Bugzilla-Version: 7.4.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: burnus at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: cc Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 09 May 2022 17:38:17 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D91544 Tobias Burnus changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |burnus at gcc dot gnu.org --- Comment #2 from Tobias Burnus --- Reconfirmed with GCC 13. Internally, the following code is generated (for my example, -fdump-tree-original): static character(kind=3D1) A.0[3][1:D.4246] =3D {"abcde", "fhji", "klmno"}; The problem is that D.4246 is a variable and not a constant. I think the pr= oper solution is to create an array for max length, i.e. 5 in this example with right padding if too short: static character(kind=3D1) A.0[3][1:5] =3D {"abcde", "fhji ", "kl= mno"}; And then in the array use, there is already some code like the following. However, here, not only the .x (=3D desired length) but also the actual len= gth (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 mat= ch either the LHS after allocation or RHS of the assignment.) .x =3D i >=3D -2 ? (integer(kind=3D8)) (i + 2) : 0; ... D.4252 =3D .x; D.4253 =3D (void *) D.4242 + (sizetype) (((S.1 + D.4249) + D.4243) * x.sp= an); D.4254 =3D (void *) &A.0[S.1]; if (D.4252 > 0) { if (NON_LVALUE_EXPR < NON_LVALUE_EXPR ) { __builtin_memmove (D.4253, D.4254, (unsigned long) NON_LVALUE_EXPR ); __builtin_memset (D.4253 + (sizetype) NON_LVALUE_EXPR , 3= 2, (unsigned long) (NON_LVALUE_EXPR - NON_LVALUE_EXPR ));=