From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp.smtpout.orange.fr (smtp-24.smtpout.orange.fr [80.12.242.24]) by sourceware.org (Postfix) with ESMTPS id D30A73858C54 for ; Sun, 6 Nov 2022 20:32:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org D30A73858C54 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=orange.fr Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=orange.fr Received: from [192.168.1.17] ([83.197.245.49]) by smtp.orange.fr with ESMTPA id rmJKotBYFUoLVrmJPoQXx5; Sun, 06 Nov 2022 21:32:12 +0100 X-ME-Helo: [192.168.1.17] X-ME-Auth: bW9yaW4tbWlrYWVsQG9yYW5nZS5mcg== X-ME-Date: Sun, 06 Nov 2022 21:32:12 +0100 X-ME-IP: 83.197.245.49 Message-ID: <2163ce95-3e4f-b887-eb35-50134bc381de@orange.fr> Date: Sun, 6 Nov 2022 21:32:05 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.1 Subject: Re: [Patch] Fortran: Fix reallocation on assignment for kind=4 strings [PR107508] To: Tobias Burnus , gcc-patches , fortran References: Content-Language: fr, en-US From: Mikael Morin In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-9.3 required=5.0 tests=BAYES_00,FREEMAIL_FROM,GIT_PATCH_0,JMQ_SPF_NEUTRAL,KAM_DMARC_STATUS,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Hello, Le 05/11/2022 à 23:28, Tobias Burnus a écrit : > Prior to the attached patch, there is a problem with realloc on assignment > with kind=4 characters as the string length was compared with the byte > size, > which was always true. > (...) > OK for mainline? > The trans-array.c part looks good. A couple of nits for the trans-expr.cc part: > diff --git a/gcc/fortran/trans-expr.cc b/gcc/fortran/trans-expr.cc > index e7b9211f17e..44c373cc495 100644 > --- a/gcc/fortran/trans-expr.cc > +++ b/gcc/fortran/trans-expr.cc > @@ -11236,10 +11236,10 @@ alloc_scalar_allocatable_for_assignment (stmtblock_t *block, > > if (expr1->ts.type == BT_CHARACTER && expr1->ts.deferred) > { > - /* Use the rhs string length and the lhs element size. */ > - size = string_length; > - tmp = TREE_TYPE (gfc_typenode_for_spec (&expr1->ts)); > - tmp = TYPE_SIZE_UNIT (tmp); > + /* Use the rhs string length and the lhs element size. Note that 'size' is > + used below for the string-length comparison, only. */ > + size = string_length, s/,/;/ ? > + tmp = TYPE_SIZE_UNIT (gfc_get_char_type (expr2->ts.kind)); Here you are using the rhs element size, which contradicts the comment, so there is certainly something to fix here (either the comment or the code). > size_in_bytes = fold_build2_loc (input_location, MULT_EXPR, > TREE_TYPE (tmp), tmp, > fold_convert (TREE_TYPE (tmp), size)); As for the testcase, do you keep the code commented on purpose? Can some of it be removed or uncommented? Mikael