From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by sourceware.org (Postfix) with ESMTPS id CA37B384D98D for ; Mon, 21 Nov 2022 10:13:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org CA37B384D98D Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com Received: by mail-wr1-x436.google.com with SMTP id z4so4494000wrr.3 for ; Mon, 21 Nov 2022 02:13:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=dWdipWIagAkdgiob0BW5NOEOLGtGXhnDWCKaVHLinKk=; b=Jg2MGrt1suDOcqjfb+V+vQT5t7pJhuMocMK1ydh7ODw7iaa0sdVN83cukejJTZEBBm o9+lzIC/JoroDSXSUaPHmGvs4Mq+Znglw1szpuZb6ifIlH+ToKnZO5Tq9DOw8AkxXnas Vdhj+s3CR1Uhl+KWN83Uk0fugi9z+QL5N1VXjsrbesYkZTp75GkUjW1ijomKi2YqzVTl VOAAgFnG45CSboBbQdxMLzLDAAOhG8RCZxiHSMk6AOytr6VWUjol4ej6kzksfvXJh4A6 k35iUaFsZfeRiTJALr3DQlXg0Tb/pF3gAH0QyVoVfxXj/DbXixQhV1hBimXr4C5t0Bk8 eQRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=dWdipWIagAkdgiob0BW5NOEOLGtGXhnDWCKaVHLinKk=; b=Dr+suZhHMU9hz/Fu0a+vy1D51/NG6jN7Wo5EJajzSMJNMI6WQaUEGtxnwiSFhR8wJ6 0K0ugPSz/1WnZracd0nWg0xl8a/Z7JMBKDkCevrz5YZQXwbPqGsH3ESxzCalbvjHub6l JkFNsfrsqYrujdHLyRlY7ySy7/c745HZMJEldtTz6DAHLG2+9lWMiGYfsq0SY69Marlq K+gflVfW2s6L2ZnTF7jNTGeiJ+5KbXc8q67mOs1+64fx7OyWGta3+msuSJKkJDDy4lqk 9ribca7IFB+Y3nEVg/sX6hA3RodHMIqxs7NPNAIGDAJL/Tg0ccc6byIE9yIHuyUA/xi/ nVIg== X-Gm-Message-State: ANoB5plka4Wt3suWZq2JkkoPkBRC6/IaNO4as3Pn9rsyHnOHI1axtCnc sDX4KHdzaPnI+Oz87R3lfJiMPP2xjfCtKw== X-Google-Smtp-Source: AA0mqf647s1Y02SCXrB7jXK4ZFkHm4Jg0R7eSUCWm2nnDNnFvDVHRwnZ2wrZ65lePoW+XLLP3r/f1Q== X-Received: by 2002:a5d:6b46:0:b0:236:56a6:823e with SMTP id x6-20020a5d6b46000000b0023656a6823emr10428225wrw.495.1669025629620; Mon, 21 Nov 2022 02:13:49 -0800 (PST) Received: from localhost.localdomain (static-176-191-105-132.ftth.abo.bbox.fr. [176.191.105.132]) by smtp.gmail.com with ESMTPSA id f16-20020a5d50d0000000b00235da296623sm10798738wrt.31.2022.11.21.02.13.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Nov 2022 02:13:49 -0800 (PST) From: =?UTF-8?q?Marc=20Poulhi=C3=A8s?= To: gcc-patches@gcc.gnu.org Cc: =?UTF-8?q?Marc=20Poulhi=C3=A8s?= Subject: [COMMITTED] ada: Reject nonconfirming Size attribute value for aliased object Date: Mon, 21 Nov 2022 11:13:46 +0100 Message-Id: <20221121101346.259079-1-poulhies@adacore.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-13.4 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,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: 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. Tested on x86_64-pc-linux-gnu, committed on master. --- 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; -- 2.34.1