From patchwork Thu Jun 20 08:53:16 2024 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: 1950020 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=adacore.com header.i=@adacore.com header.a=rsa-sha256 header.s=google header.b=jGmDnUMZ; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4W4ZdH1jFVz20X6 for ; Thu, 20 Jun 2024 19:17:23 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4C49F38930FE for ; Thu, 20 Jun 2024 09:17:21 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-lf1-x133.google.com (mail-lf1-x133.google.com [IPv6:2a00:1450:4864:20::133]) by sourceware.org (Postfix) with ESMTPS id DE7963888C7D for ; Thu, 20 Jun 2024 08:53:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DE7963888C7D Authentication-Results: sourceware.org; dmarc=pass (p=quarantine 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 DE7963888C7D Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::133 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1718873642; cv=none; b=D9LXNZFkSXByXpKsTHTMJs2RaTPfh9hkb3aMy3x6TzNkqV3vi5odL33O/TIce42i962mfK1HT5zDApeSpc9PEkX0jk0z6IMY0ALbMoaERzBICGo954TdeNE/OK5TiAGrymqF/A8/Q2Y+CS+Qy59bhuuF44PJAkQE547hGniV/GU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1718873642; c=relaxed/simple; bh=Ssn5e0em+z7ZLq+v+hkTdjvWVSDQSKk/12Ww+CXhqjI=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=wVX7tQh2EJx5G5ccqJEn61TalA3OGZMCNbBeXYUU3UDr4dtRl1NsvbPj1XOi9o0zu82zQ0AO6VEvugCpJHfBziNb507UE33olx7x0CZ/Z9A5EsnAr0YW8JBw2WqWpi8KKaX+9l6vIU1UmzNR3lMLR0ABrenczqB5Vl61zoSluBY= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-lf1-x133.google.com with SMTP id 2adb3069b0e04-52c8342af5eso683480e87.3 for ; Thu, 20 Jun 2024 01:53:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1718873634; x=1719478434; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=gpp359zHPq3JnydPsljNd5F34/3HCUlNneJdLA/V3dA=; b=jGmDnUMZxC2nBrecaQdDcsTnAcGjsG3UZ1K7gemwzRLGsv3xD/jSqh2DSOB/3mmmBh i8iRBoLPrRN+TL1MIGuP5jrGhaj5C7xHs341sa2uJKCxC3kieG0LjelJ8SBOJ0Pfu7f1 pl4mXwBXg7xf2vUSl88qd+YudqL5fMepVb2ohTjh26REA95gJKZWMAyBZZAhD3alhxRV lDEV0UddY3KjEwQBYEZNA7Pm371B4v9Y6GMGO4/i0H/1N+/d/rPtxlwU4SGgONzwOVeO RHOHFgW0Nv1pIyi2G+qC0ePdqdBQL2g5r0EaE7SzDAQs7wUgYDhCeaztkUUURj0S6Fhj 4KbQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718873634; x=1719478434; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=gpp359zHPq3JnydPsljNd5F34/3HCUlNneJdLA/V3dA=; b=hI3uHpLiRi+G+B6fhTNhAWf2LyDMeLezDHBYaOL16xbaIaN+A1rmWXp6+Bf2Jp1Gex BjepxFfL0aZrxhQ7tkGwELOZBI3hR6PvyALDhVt0ydoy1kcYIr8Y/eZrensbtWPDNPvR owSIEXuYmwVCUA/cSg9GwlxX7sJpdeNtCnt6oSRJjv7HGypopXf2aFdjwZgHdKz9sFVO fOArRaef0WdN7J+SEJsHH06u2nPjXcuuXz6Pgzqua+msnqQ9vlVgi/QGexB3phg8G3ph MrvvmPF0Be+ijzyllnRk9uwrbiBQ7fyrgcza34v2rsFkSFMVsK5EVtkdIzICDpl8/3/S QHfA== X-Gm-Message-State: AOJu0YxYE3MlGyVS3TcL+i1U7T/vH2aekaPzWEcw5uBjoeME7LNQPstB DrR9MZ/XLqQl/w6bJG0gyV6iYwQFSXI+47EEDOo+7XCKs9OsKKQM4b5k+VdNeaHH/YDs5oAdrvo = X-Google-Smtp-Source: AGHT+IH3hfdzGbWSt1PwXhDcVhgXI+xFQRnwyhiQS4mXNeQYoE2LMTfO6EalgC0lEOgKDxTtINULWA== X-Received: by 2002:a05:6512:a92:b0:52c:851a:a0f2 with SMTP id 2adb3069b0e04-52ccaa57aa5mr3319378e87.50.1718873634273; Thu, 20 Jun 2024 01:53:54 -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 ffacd0b85a97d-363c795febfsm3305522f8f.104.2024.06.20.01.53.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jun 2024 01:53:53 -0700 (PDT) From: =?utf-8?q?Marc_Poulhi=C3=A8s?= To: gcc-patches@gcc.gnu.org Cc: Gary Dismukes Subject: [COMMITTED 26/30] ada: Crash on selected component of formal derived type in generic instance Date: Thu, 20 Jun 2024 10:53:16 +0200 Message-ID: <20240620085321.2412421-26-poulhies@adacore.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240620085321.2412421-1-poulhies@adacore.com> References: <20240620085321.2412421-1-poulhies@adacore.com> 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+incoming=patchwork.ozlabs.org@gcc.gnu.org From: Gary Dismukes The compiler crashes on an instantiation of a generic child unit G1.GC that has a formal private extension P_Ext of a private type P declared in the parent G1 whose full type has a component C, when analyzing a selected component ACC.C whose prefix is of an access type coming from an instantiation of another generic G2 where the designated type is the formal type P_Ext (coming in from a formal type of G2). gcc/ada/ * sem_ch4.adb (Try_Selected_Component_In_Instance): Reverse if_statement clauses so that the testing for the special case of extensions of private types in instance bodies is done first, followed by the testing for the case of a parent type that's a generic actual type. In the extension case, apply Base_Type to the type actual in the test of Used_As_Generic_Actual, and add a test of Present (Parent_Subtype (Typ)). Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/sem_ch4.adb | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/gcc/ada/sem_ch4.adb b/gcc/ada/sem_ch4.adb index e75f8dfb6bc..1175a34df21 100644 --- a/gcc/ada/sem_ch4.adb +++ b/gcc/ada/sem_ch4.adb @@ -5237,22 +5237,6 @@ package body Sem_Ch4 is end if; end loop; - -- If Par is a generic actual, look for component in ancestor types. - -- Skip this if we have no Declaration_Node, as is the case for - -- itypes. - - if Present (Par) - and then Is_Generic_Actual_Type (Par) - and then Present (Declaration_Node (Par)) - then - Par := Generic_Parent_Type (Declaration_Node (Par)); - loop - Find_Component_In_Instance (Par); - exit when Present (Entity (Sel)) - or else Par = Etype (Par); - Par := Etype (Par); - end loop; - -- Another special case: the type is an extension of a private -- type T, either is an actual in an instance or is immediately -- visible, and we are in the body of the instance, which means @@ -5263,12 +5247,29 @@ package body Sem_Ch4 is -- the Has_Private_View mechanism is bypassed because T or the -- ancestor is not directly referenced in the generic body. - elsif Is_Derived_Type (Typ) - and then (Used_As_Generic_Actual (Typ) + if Is_Derived_Type (Typ) + and then (Used_As_Generic_Actual (Base_Type (Typ)) or else Is_Immediately_Visible (Typ)) and then In_Instance_Body + and then Present (Parent_Subtype (Typ)) then Find_Component_In_Instance (Parent_Subtype (Typ)); + + -- If Par is a generic actual, look for component in ancestor types. + -- Skip this if we have no Declaration_Node, as is the case for + -- itypes. + + elsif Present (Par) + and then Is_Generic_Actual_Type (Par) + and then Present (Declaration_Node (Par)) + then + Par := Generic_Parent_Type (Declaration_Node (Par)); + loop + Find_Component_In_Instance (Par); + exit when Present (Entity (Sel)) + or else Par = Etype (Par); + Par := Etype (Par); + end loop; end if; return Etype (N) /= Any_Type;