From patchwork Mon May 29 08:29:21 2023 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: 70218 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 9BCF438845A5 for ; Mon, 29 May 2023 08:33:25 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9BCF438845A5 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1685349205; bh=FMp7KAU3vkD4mQmreC7NFeAu9ckqMfh7PfTNzX5byew=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=rHyNwQAZg7fbPCy+sRoMmDOJb42edTrkGKlIVga6n8YpsBiaodFMlHnoyvvsJbrjm MV5+DHY2qsOKzWHkTyCYXUqpm/oAGeqWSBlWG0epsqPQbn7rsQP1md5ET9iQpAbrVb e+D8o2y/8Xsf+qdhh9UOm+tuD5dK6CI6+OAPGlLo= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by sourceware.org (Postfix) with ESMTPS id 40C96384DA5B for ; Mon, 29 May 2023 08:29:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 40C96384DA5B Received: by mail-wr1-x42e.google.com with SMTP id ffacd0b85a97d-30ad458f085so1931508f8f.0 for ; Mon, 29 May 2023 01:29:24 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685348963; x=1687940963; 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=FMp7KAU3vkD4mQmreC7NFeAu9ckqMfh7PfTNzX5byew=; b=QuonCWQcrLJsfeXbOPeYRzF66yQBsOV60aQ6dyqWk3DQyoufVCeIP77pI6tUkZTN+g 21L0FksjkoIEi4sQp1zcEUqN50QnrRHsRO1wVjNRyyAyCjSpI+vB95m/T64/cq1l8UYQ lQyC5cxeCXg6uNd6kWSUx5HVzwznDq46Cj3gT9zDcn1dtfaEq7e51Wkp+jWlSFv8mY44 zgvyNftoJvs/VL8vPwM5lNFsUfHLMjrj+qvl5Behd+TdBolyPtIngP9gvuqCPu7G7eKE PwNExbdaGxrw0w7gUSfBf0OCMZMQObGLB55vy7U3FAlYKx1q68CBNzQs5NX45INb9RLc 69jA== X-Gm-Message-State: AC+VfDxWj2WaCcg+BLYEWU1+QYVZ9dhL/n7SXcPH8ylZkBe8DM+Yk5bS zsnPJYob2K8TmgJj0ILfbjBZn9rZjpC7bnBafTX0Eg== X-Google-Smtp-Source: ACHHUZ6QT+PhVWjoUemyM0QtMnwpTnufIz7Sbr6QBlQUN5SKypJIMgnvLkoLyLdvBkNUOtEVKhWjpQ== X-Received: by 2002:a5d:63ce:0:b0:30a:8999:3b9 with SMTP id c14-20020a5d63ce000000b0030a899903b9mr6307306wrw.28.1685348963065; Mon, 29 May 2023 01:29:23 -0700 (PDT) Received: from poulhies-Precision-5550.telnowedge.local (lmontsouris-659-1-24-67.w81-250.abo.wanadoo.fr. [81.250.175.67]) by smtp.gmail.com with ESMTPSA id f10-20020a7bc8ca000000b003f42ceb3bf4sm13320910wml.32.2023.05.29.01.29.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 May 2023 01:29:22 -0700 (PDT) To: gcc-patches@gcc.gnu.org Cc: =?utf-8?q?Marc_Poulhi=C3=A8s?= Subject: [COMMITTED] ada: Fix crash on vector initialization Date: Mon, 29 May 2023 10:29:21 +0200 Message-Id: <20230529082921.2410077-1-poulhies@adacore.com> X-Mailer: git-send-email 2.40.0 MIME-Version: 1.0 X-Spam-Status: No, score=-13.7 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, T_SCC_BODY_TEXT_LINE 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" Initializing a vector using Vec : V.Vector := [Some_Type'(Some_Abstract_Type with F => 0)]; may crash the compiler. The expander marks the N_Extension_Aggregate for delayed expansion which never happens and incorrectly ends up in gigi. The delayed expansion is needed for nested aggregates, which the original code is testing for, but container aggregates are handled differently. Such assignments to container aggregates are later transformed into procedure calls to the procedures named in the Aggregate aspect definition, for which the delayed expansion is not required/expected. gcc/ada/ * exp_aggr.adb (Convert_To_Assignments): Do not mark node for delayed expansion if parent type has the Aggregate aspect. * sem_util.adb (Is_Container_Aggregate): Move... * sem_util.ads (Is_Container_Aggregate): ... here and make it public. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/exp_aggr.adb | 7 +++++-- gcc/ada/sem_util.adb | 3 --- gcc/ada/sem_util.ads | 3 +++ 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/gcc/ada/exp_aggr.adb b/gcc/ada/exp_aggr.adb index a6a7d810185..75e5e1402df 100644 --- a/gcc/ada/exp_aggr.adb +++ b/gcc/ada/exp_aggr.adb @@ -5000,9 +5000,12 @@ package body Exp_Aggr is if -- Internal aggregate (transformed when expanding the parent) + -- excluding the Container aggregate as these are transformed to + -- procedure call later. - Parent_Kind in - N_Aggregate | N_Extension_Aggregate | N_Component_Association + (Parent_Kind in + N_Component_Association | N_Aggregate | N_Extension_Aggregate + and then not Is_Container_Aggregate (Parent_Node)) -- Allocator (see Convert_Aggr_In_Allocator) diff --git a/gcc/ada/sem_util.adb b/gcc/ada/sem_util.adb index 64abfb11ce5..a42b2dff60f 100644 --- a/gcc/ada/sem_util.adb +++ b/gcc/ada/sem_util.adb @@ -132,9 +132,6 @@ package body Sem_Util is -- Determine whether arbitrary entity Id denotes an atomic object as per -- RM C.6(7). - function Is_Container_Aggregate (Exp : Node_Id) return Boolean; - -- Is the given expression a container aggregate? - generic with function Is_Effectively_Volatile_Entity (Id : Entity_Id) return Boolean; diff --git a/gcc/ada/sem_util.ads b/gcc/ada/sem_util.ads index b5bcd267e33..d1bbc6af0e8 100644 --- a/gcc/ada/sem_util.ads +++ b/gcc/ada/sem_util.ads @@ -1475,6 +1475,9 @@ package Sem_Util is -- Return True if the loop has no side effect and can therefore be -- marked for removal. Return False if N is not a N_Loop_Statement. + function Is_Container_Aggregate (Exp : Node_Id) return Boolean; + -- Is the given expression a container aggregate? + function Is_Newly_Constructed (Exp : Node_Id; Context_Requires_NC : Boolean) return Boolean; -- Indicates whether a given expression is "newly constructed" (RM 4.4).