From patchwork Mon Nov 21 10:13:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Marc_Poulhi=C3=A8s?= X-Patchwork-Id: 60909 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 03DCF382FC97 for ; Mon, 21 Nov 2022 10:15:11 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 03DCF382FC97 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1669025711; bh=dWdipWIagAkdgiob0BW5NOEOLGtGXhnDWCKaVHLinKk=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=REhtYiwwTIND+rQVmq0nHqC6bPKjMiYCVNNFhzxl7bF7Q2KFCF7uMtoWTds8tUPqU 5RJcnqbsRIzd+dsyfTWQz19kHDei78nYeeRV0qwZlObD5SJcU1YGtGQBK68+pDB4sw lkAtSnO6PmNnSsROBNKfE9lHxGzzh7sy9wQ3SipU= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org 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 Received: by mail-wr1-x436.google.com with SMTP id z4so4494000wrr.3 for ; Mon, 21 Nov 2022 02:13:50 -0800 (PST) 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) To: gcc-patches@gcc.gnu.org Cc: =?utf-8?q?Marc_Poulhi=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 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: =?utf-8?q?Marc_Poulhi=C3=A8s_via_Gcc-patches?= From: =?utf-8?q?Marc_Poulhi=C3=A8s?= Reply-To: =?utf-8?q?Marc_Poulhi=C3=A8s?= Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" 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;