From patchwork Thu Nov 30 10:19:00 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: 81008 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 A8B063861876 for ; Thu, 30 Nov 2023 10:19:27 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by sourceware.org (Postfix) with ESMTPS id 3C8233858287 for ; Thu, 30 Nov 2023 10:19:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3C8233858287 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 3C8233858287 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::42f ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701339545; cv=none; b=fw0boAvKpkgxFU3BWG7MRh3Y7gyCiE7Lk0kEF4PJeWUrKwo1NHv9cQywHddIcHw1k8Tui2JLqi9QEg2uRTsiWo+cy3AAJRS24nHJV3NlUtcqyQhK5jV5Ix1n2VOzWnWDkTcArufXPzYtPT0IxagoLSmtZLeznQ3L935GLvQt4ow= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701339545; c=relaxed/simple; bh=jh6QBjpVOEpO4jbBWrsGsMYVPGQsTE+B6+06C95tboc=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=P6wJFrVxbttV4vWTINxShU6KO+0iSYd12b2CVIZuunwVOayBObhJGbADyxP/zfiSSWHW5oc+Nh34bU16Io1DzbYseyAR0pNMx3ZScWFgNzSa1tfa/UmgRln79drZ/b+Nkvpo/GcrKLYdfVJ+aDeKraGbvQLYGaVgCIDE7UdyHes= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wr1-x42f.google.com with SMTP id ffacd0b85a97d-332ddd8e0bdso1172319f8f.0 for ; Thu, 30 Nov 2023 02:19:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1701339542; x=1701944342; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=dqYMsR5N7raNTgA+cLmyjFPLnMsxxyz9KAINHW7/0ms=; b=jXznRdlzpQQUtVk5wFqPlIdRQ5NAf6ZX7RHYgNBRv29Yp8fMS5oLdJvCOZH8o5ruWt JlqElaSBveF9ToAO7H07526GrrrVBrBTWveCwbYdNdwh7XpCR/daUynFDkbdmfZIrP5m ahe8LFcOxdFd/0sjHy637Y0fixSSnUKSEo6gp5RRdOWtF4j2NurzM2aGbSMedshGkKB7 Yl2Y0wn9itf6TRJIdBVBB3jIvNN87FBzg4xfqwbtGhGCiUZuqC2uBuaiMV7S6A/AMapS I68DKHrVn1mHawPRekHvQdBNKNkqgnXeoijK+ivZVJQsY7GKkSBxUKgTus9cXrfeTzzw Dv2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701339542; x=1701944342; 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=dqYMsR5N7raNTgA+cLmyjFPLnMsxxyz9KAINHW7/0ms=; b=Ex+0bvrSXb1X3Prfx3SboTjVkODWgjpcwTLgXGxgbI/GfYUWiWY4Q7ovACYz5ZcNsm BU2tTXp3fCErcN9GQtm4snyu3dEeoXq9oWzFwzRhgC+NOXl9y5R8xf5C685yK0ja6vT2 gY3hIg/EiXad76jI+AuBnKSGBgKWtWZdhIvQ48fDM7MK7UXDjkMKUcqSnK9kWQEoAnX1 1aw340O50qE2cEpODcdXTZJXbmGoz5wahxpbuprOA4Pr289gHxMqrCUPmn0C4vs/KykM IGxMXHPSg9HFauwsaeaz9SrgeActaAfPpOPKxpRR4P6a12QE+S2yiOqnZkhQyqKOp3Ox YaQA== X-Gm-Message-State: AOJu0YwYkKJ0Y/QPfLFijLUl9ucigkeOsAI42kKi3XhpRf4G3yGZW0gI KRPPHMTV7p14Dg+ll/SiUIvvyxcolT/sOtZWJMx2Ow== X-Google-Smtp-Source: AGHT+IEVoMdoVTMlVdjAcPADXNqsuwumnEH3RG7gM2maDR9ttVNC+hz75js8sOlyZ6OPze1FuEzLTw== X-Received: by 2002:a05:6000:10d2:b0:332:c6cf:320d with SMTP id b18-20020a05600010d200b00332c6cf320dmr15983228wrx.15.1701339541800; Thu, 30 Nov 2023 02:19:01 -0800 (PST) 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 l5-20020a5d5605000000b003330f9287a6sm1115551wrv.11.2023.11.30.02.19.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Nov 2023 02:19:01 -0800 (PST) From: =?utf-8?q?Marc_Poulhi=C3=A8s?= To: gcc-patches@gcc.gnu.org Cc: Eric Botcazou Subject: [COMMITTED] ada: Fix wrong finalization for qualified aggregate of limited type in allocator Date: Thu, 30 Nov 2023 11:19:00 +0100 Message-ID: <20231130101900.3093876-1-poulhies@adacore.com> X-Mailer: git-send-email 2.42.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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org From: Eric Botcazou This happens with -gnata when the limited type has controlled components and a predicate, because the predicate check generated for the aggregate causes the creation of a temporary that is used as the expression of the allocator. Now this combination is illegal for a limited type, so the compiler does not generate the deep adjustment that would be necessary for the access value, which ultimately results in a wrong finalization. gcc/ada/ * checks.adb (Apply_Predicate_Check): Also deal specifically with an expression that is a qualified aggregate in an allocator. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/checks.adb | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/gcc/ada/checks.adb b/gcc/ada/checks.adb index 6525982aef9..84a21b2c177 100644 --- a/gcc/ada/checks.adb +++ b/gcc/ada/checks.adb @@ -2851,6 +2851,27 @@ package body Checks is (Typ, Duplicate_Subexpr (Name (Par)))); return; + -- Similarly, if the expression is a qualified aggregate in an + -- allocator, apply the check to the dereference of the access + -- value, rather than create a temporary. This is necessary for + -- inherently limited types, for which the temporary is illegal. + + elsif Nkind (Par) = N_Allocator then + declare + Deref : constant Node_Id := + Make_Explicit_Dereference (Sloc (N), + Prefix => Duplicate_Subexpr (Par)); + + begin + -- This is required by Predicate_Check_In_Scope ??? + + Preserve_Comes_From_Source (Deref, N); + + Insert_Action_After (Parent (Par), + Make_Predicate_Check (Typ, Deref)); + return; + end; + -- Similarly, if the expression is an aggregate in an object -- declaration, apply it to the object after the declaration.