From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from esa3.mentor.iphmx.com (esa3.mentor.iphmx.com [68.232.137.180]) by sourceware.org (Postfix) with ESMTPS id 8A5A53858C56; Mon, 28 Mar 2022 10:05:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 8A5A53858C56 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=mentor.com X-IronPort-AV: E=Sophos;i="5.90,217,1643702400"; d="scan'208";a="73512547" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa3.mentor.iphmx.com with ESMTP; 28 Mar 2022 02:05:36 -0800 IronPort-SDR: mBs8aKjUKteaJBoLb7TtmQh5mQ6AcDsdEC/2afwddO1vIb754c0O4ymz+CIuXLTaujI/AZN8ED z0Hl5VRF+P0iE5NJH1R2EM4a9QPtSRM6zhDQAhO7jjjZGSei5PPIIM44oW4lDNgEgR13eXLDCB vHVW878S8xwbM03p6w+mHGTOAQmVuSx30F5m0Y5mQlTia77musbL5zkIRtrLbQc9mQoL2KQ1Bb QFaD6SCPK5EzXZoh6oeJUkMYu4bHWuqcLzxjzUsVzkz6IEQFLLr9dl78/Z5mD/6wT+snvPPYe3 j5A= Message-ID: <5a7fa9f6-7155-9dc6-d847-e44ccccb447a@codesourcery.com> Date: Mon, 28 Mar 2022 12:05:30 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.7.0 Subject: Re: [PATCH] PR fortran/50549 - should detect different type parameters in structure constructors Content-Language: en-US To: Harald Anlauf , fortran , gcc-patches References: From: Tobias Burnus In-Reply-To: Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: quoted-printable X-Originating-IP: [137.202.0.90] X-ClientProxiedBy: svr-ies-mbx-06.mgc.mentorg.com (139.181.222.6) To svr-ies-mbx-01.mgc.mentorg.com (139.181.222.1) X-Spam-Status: No, score=-5.4 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, KAM_SHORT, NICE_REPLY_A, SPF_HELO_PASS, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: fortran@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Fortran mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 28 Mar 2022 10:05:39 -0000 Hi Harald, On 27.03.22 21:44, Harald Anlauf via Fortran wrote: > when assigning character pointers, we have a check for same length, > which however does not trigger for character pointers within a > structure constructor. > > The attached patch extends the character checks slightly to fix > this loophole. I've verified that NAG and Crayftn behave similarly, > while Intel does not detect the length difference. > > Regtested on x86_64-pc-linux-gnu. > > OK for mainline? Thanks for the patch! LGTM and I think GCC 12 is still okay. However, I have a nit: > --- a/gcc/fortran/resolve.cc > +++ b/gcc/fortran/resolve.cc > @@ -1375,11 +1375,22 @@ resolve_structure_cons (gfc_expr *expr, int init) > ... > + long len_a, len_b; > + len_a =3D mpz_get_si (comp->ts.u.cl->length->value.integer); > + len_b =3D mpz_get_si (cons->expr->ts.u.cl->length->value.inte= ger); > + gfc_error ("Unequal character lengths (%ld/%ld) for pointer " > + "component %qs in constructor at %L", > + len_a, len_b, comp->name, &cons->expr->where); 'long' might be int32_t instead of int64_t (e.g. on Windows, I think both MinGW32 and MinGW64, but I am not quite sure). Thus, I wonder whether it makes more sense to use: HOST_WIDE_INT, gfc_mpz_get_hwi() and '%wd' I note that '%wd' (and '%lld') is only supported since last August (commit https://gcc.gnu.org/r12-3044-g1b507b1e3c5 ), but now that it is, I think we should use it at places where the value can be larger than INT_M= AX. I think at some point, we should also check the rest of the code and change those mpz_get_si to gfc_mpz_get_hwi which can exceed INT_MAX. Likewise, some of the %ld/%lu or %lld/%llu code should be also converted to= %wd/%wu. Tobias PS: For using HWI with 'sprintf' instead of diagnostic's error/warning, HOST_WIDE_INT_PRINT_DEC exists and has to be used. ----------------- Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstra=C3=9Fe 201= , 80634 M=C3=BCnchen; Gesellschaft mit beschr=C3=A4nkter Haftung; Gesch=C3= =A4ftsf=C3=BChrer: Thomas Heurung, Frank Th=C3=BCrauf; Sitz der Gesellschaf= t: M=C3=BCnchen; Registergericht M=C3=BCnchen, HRB 106955