From patchwork Tue Sep 21 15:25:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierre-Marie de Rodat X-Patchwork-Id: 1530761 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=adacore.com header.i=@adacore.com header.a=rsa-sha256 header.s=google header.b=c+CWlEnD; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from 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 RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4HDQJc6nXyz9sW5 for ; Wed, 22 Sep 2021 01:26:56 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3A37C385842E for ; Tue, 21 Sep 2021 15:26:54 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by sourceware.org (Postfix) with ESMTPS id BE2D33858422 for ; Tue, 21 Sep 2021 15:26:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org BE2D33858422 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com Received: by mail-wr1-x429.google.com with SMTP id q26so40306001wrc.7 for ; Tue, 21 Sep 2021 08:26:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; h=date:from:to:cc:subject:message-id:mime-version:content-disposition; bh=TIhlkuP7C80VvBSYRJssnxSYxO+ff+OzhS0RHPDB81w=; b=c+CWlEnDFBS7HRrZtnv2oNzqFV8k8YHEhu6IEvi6iu01Z3KNUy6Yulj9mTXoXtSG5P efC+y5vXW1k51FWrhb7Bhb//DiFZo5j6r2p9WDKM4ILyYHds5G+al40l2/JFPGxHgVZi cuPPtJPHzo4Hm0XhR5hKT9l4Eh9EDY45zensBEQmuDaAG2L3hbD/qpLFbqDp1TnHfZHF 8vDhqeTYp6irKtv3UrlNMegNccQV73XEClz6b0ZAK/8r2MA3WocnKSPxUYUi5g8FshcS /4Gx12SIkgIlSGrue4VEccAZXZKqUtkoR1k5m9Tnp3UkkRYif/F/k0a8vNUUu+logmJw 4N9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition; bh=TIhlkuP7C80VvBSYRJssnxSYxO+ff+OzhS0RHPDB81w=; b=zzkbR0RlJvb42bc7wOCJFl6eJDC6W7TIVUSAzuW6S252YHmgXY4PqrovvHwen0VCG1 EeD3no6wlAJP009SwEXlEeSLMZ0uSkU6ujv7UzrszDk3upKvferrA7cDjJTkbRrYY0C8 6ViGY/z1DfTo3e5Z+4/UDJrt9GiJQ4OxQ0vHOOdAIv0JvT3918HVJ/m+O7jb6tAWYZ4Y JdJcqICSwTUysSlymjTpvy8AJOwdWGwNn9HfPhS1fp4AZsnTnZgbfIPdHqPQfSA/he0Q MF2mIB4Fur7vd//fp04AKBFUKcE6tY7ft6cbvlgra2vB+kpKbDTEvfuTDoE3l90iwbiS GJJw== X-Gm-Message-State: AOAM533gIrvU9ujvXGFY1QOoHQziIhdNdRu2RiAxVBpJxVOF/TCB9r7r KOY3dQr2y7ZGCKhYqduq91VyTV7qg5JYRw== X-Google-Smtp-Source: ABdhPJwN6SiuTQYjNIR+9XzeN8ubfyfbXnfdSWJSGVCPM2dApoA47qT3G+T2VsqQG9OtEMlzGiEdxA== X-Received: by 2002:a7b:c74b:: with SMTP id w11mr5289352wmk.21.1632237959668; Tue, 21 Sep 2021 08:25:59 -0700 (PDT) Received: from adacore.com ([2a02:2ab8:224:2ce:72b5:e8ff:feef:ee60]) by smtp.gmail.com with ESMTPSA id z5sm3504781wmp.26.2021.09.21.08.25.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Sep 2021 08:25:58 -0700 (PDT) Date: Tue, 21 Sep 2021 15:25:58 +0000 From: Pierre-Marie de Rodat To: gcc-patches@gcc.gnu.org Subject: [Ada] Refine patch for spurious link error involving discriminated types Message-ID: <20210921152558.GA3094503@adacore.com> MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-12.9 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.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: , Cc: Ed Schonberg Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" This patch handles properly the case of a Component_Definition appearing in a Component_Declaration. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * sem_ch3.adb (Process_Discriminant_Expressions): If the constraint is for a Component_Definition that appears in a Component_Declaration, the entity to be used to create the potentially global symbol is the Defining_Identifier of the Component_Declaration. diff --git a/gcc/ada/sem_ch3.adb b/gcc/ada/sem_ch3.adb --- a/gcc/ada/sem_ch3.adb +++ b/gcc/ada/sem_ch3.adb @@ -10502,13 +10502,30 @@ package body Sem_Ch3 is if Expander_Active and then Comes_From_Source (Def) and then not Is_Subprogram (Current_Scope) - and then Nkind (Parent (Def)) in - N_Object_Declaration | N_Component_Declaration then - Force_Evaluation ( - Discr_Expr (J), - Related_Id => Defining_Identifier (Parent (Def)), - Discr_Number => J); + declare + Id : Entity_Id := Empty; + begin + if Nkind (Parent (Def)) = N_Object_Declaration then + Id := Defining_Identifier (Parent (Def)); + + elsif Nkind (Parent (Def)) = N_Component_Definition + and then + Nkind (Parent (Parent (Def))) + = N_Component_Declaration + then + Id := Defining_Identifier (Parent (Parent (Def))); + end if; + + if Present (Id) then + Force_Evaluation ( + Discr_Expr (J), + Related_Id => Id, + Discr_Number => J); + else + Force_Evaluation (Discr_Expr (J)); + end if; + end; else Force_Evaluation (Discr_Expr (J)); end if;