From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7871) id D43733857C51; Mon, 21 Nov 2022 10:12:52 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D43733857C51 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1669025572; bh=Z9oE5Cg8/pVh+gL0rphyuFK7sHL46eXR0n94gJqEwl0=; h=From:To:Subject:Date:From; b=dPUG17WDWRRiXyYDL310cx/jOUc20OLyC+Td0oVvd5mQ/Lzlj/0Bup9BcE1ymZhTq WiaPJ/hskrPEjlC+IGaEnSbVWN/l3KLbpSJzBpvaqvpdN3EQqdkeceEh1e3/4WbICS kQW928Tou651eK4xnYlV3D0aTJ4KplMPE+ODwLWg= MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="utf-8" From: Marc Poulhi?s To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-4190] ada: Reject nonconfirming Size attribute value for aliased object X-Act-Checkin: gcc X-Git-Author: =?utf-8?q?Marc_Poulhi=C3=A8s?= X-Git-Refname: refs/heads/master X-Git-Oldrev: 6d0d71ea1c685df245f3c11a5daf52843823cd58 X-Git-Newrev: 493e760dda4dac45eefac4185a7b04a1b8fc6c18 Message-Id: <20221121101252.D43733857C51@sourceware.org> Date: Mon, 21 Nov 2022 10:12:52 +0000 (GMT) List-Id: https://gcc.gnu.org/g:493e760dda4dac45eefac4185a7b04a1b8fc6c18 commit r13-4190-g493e760dda4dac45eefac4185a7b04a1b8fc6c18 Author: Marc Poulhiès Date: Mon Nov 7 14:34:54 2022 +0100 ada: Reject nonconfirming Size attribute value for aliased object Only confirming Size must be supported for aliased object of elementary type (see RM 13.1 in the "Implementation Advice"). -- size is 1-byte type Y is range 0 .. 20; type Ay is access all Y; -- Var size is 8-bytes Var : aliased Y := 5 with Size => 64; -- JP.all is a 1-byte reference to an 8-bytes objects. JP : Ay := Var'Access; The above JP.all references the first byte of the 8-byte Var object, which is, for example, not correct on little-endian systems. This change rejects nonconfirming Size attribute on such objects instead of miscompiling it. gcc/ada/ * sem_ch13.adb (Check_One_Attr): produce error when Size attribute used on aliased object of elementary types with nonconfirming value. Diff: --- gcc/ada/sem_ch13.adb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/gcc/ada/sem_ch13.adb b/gcc/ada/sem_ch13.adb index 5507353136b..bf84a10ded6 100644 --- a/gcc/ada/sem_ch13.adb +++ b/gcc/ada/sem_ch13.adb @@ -7310,6 +7310,21 @@ package body Sem_Ch13 is Set_Esize (U_Ent, Size); end if; + -- As of RM 13.1, only confirming size + -- (i.e. (Size = Esize (Etyp))) for aliased object of + -- elementary type must be supported. + -- GNAT rejects nonconfirming size for such object. + + if Is_Aliased (U_Ent) + and then Is_Elementary_Type (Etyp) + and then Known_Esize (U_Ent) + and then Size /= Esize (Etyp) + then + Error_Msg_N + ("nonconfirming Size for aliased object is not " + & "supported", N); + end if; + Set_Has_Size_Clause (U_Ent); end; end if;