From patchwork Tue Aug 6 09:02:38 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: 1969385 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=VA1QyoB4; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; 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 [8.43.85.97]) (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 4WdS7P2Y2Xz1yYD for ; Tue, 6 Aug 2024 19:05:05 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9F950385DDFE for ; Tue, 6 Aug 2024 09:05:03 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) by sourceware.org (Postfix) with ESMTPS id E301E385C6C6 for ; Tue, 6 Aug 2024 09:03:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E301E385C6C6 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 E301E385C6C6 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::32c ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1722935010; cv=none; b=noCh0sgBlNkVHgUiocvwOi8ASjL85zABy6hrq3idvSlQU5+m7VP2AtTmoUUFTaGup/EtaPgIuEbgXI4dnrNbtGpUbmWFKbccIDoyzw7T5hn7McuB+ftLNtMV+8dxH23w9otY3RD5XS6YEl1G0NqLVqxKQPARp35potzBuQxsnQQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1722935010; c=relaxed/simple; bh=bkXD4OgGryqy58JcV1kAM6GXtNXLSHKRYIsrm1Mrfvo=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=QUB/LEmcIKLMdjQ2biutRF+sGEmdS+u0sJ2qWZW2OCqbASla452tkJPILH5lr/jceDE0gG/tOLCAtoR6HLK1ZyxHuH1rVSYH62JFBNw20iJLX5i6MpZG+lBWU5B8bK+Jb1EhagQYuRDPAq+6gIZqAv+Eel7qZBTGJgm0+jW2NJo= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wm1-x32c.google.com with SMTP id 5b1f17b1804b1-4281faefea9so2042455e9.2 for ; Tue, 06 Aug 2024 02:03:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1722935007; x=1723539807; 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=zCUlRVUyb37JjBzIrqp5J5a9VZxHGaXKw+JB8Ng6mx0=; b=VA1QyoB46aNtbixFw9YsP9NHbTTuOuMw3c1BQpvNFKoiHIHEBbg/elR9HO2EM6U78a jiNMnEmX/RUt1sFXT0I3692/aEGAtVkpNJjFqViDWrrPQLfK4RX1JCJHZSQCXGpFwWHd fH98IOX+evW5TPf0sQxm0hF4R2wIeoHfmZRWLCBQIoY4ESNSTJsnSxZkIOoXV2E9A3yT GpGYdTovtZeGu93b2wZ2jcKQBGuMN3jveJ2PJURrnNREk+j5z3/OwO0fuHgzlNWNNCXn g2boU+MIgNJxeRv4EJnhkxvDn8h2PXDvwTCNtlaNVqhh+N5Rwt4dV/YQqRPMBtF6WBT/ YDHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722935007; x=1723539807; 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=zCUlRVUyb37JjBzIrqp5J5a9VZxHGaXKw+JB8Ng6mx0=; b=SQGazgm0QTdS95nmT3SshhEZhRhg3VTVWK9L2M2KUcJ0RdcU6D0ANtRmVthjtYe4DM X4RJuUFoO1lyQppR7DvZblxowyy2m6KG/azb9El/je2jZVGsA6RC/EKKcU6QHBe1o3jg yZFBDuoIiZhziCjYdRAqWEvIi6175TzYcdGtXK/WHS7mXyv4bBrL0so81xqh876PR/CH cyXMpo651Us0SCvLKhQay1i1evpvSoJquUejC+cJyjNVgodGztuS5RICWXP9lqmjLsTS JsC8CRiWYt+aD5vPbQD0ivx76pQg1OsaC0W+T3/0cH/DhqkxE2sZH3g8KiZs0mINs1zj UwZA== X-Gm-Message-State: AOJu0YxkMU0Z8Jv6PXVC1ZyyxOSx9gSRCi27eSfQKj7oxCGZ2Q7UftTg TeohRMvizr33afMyPNIhZgcbqpwUGyi3Vuk0VGgXv4/9bwCal216eRydZhDEh9+cdcWgvQ5SWUT 6Ww== X-Google-Smtp-Source: AGHT+IGCk0rsGqzYvuA7n3dvdZU2VNDxHp5MD0jVa28xMGXgOEmleYDo8cOdutAbQeBuQ/osFAFRLw== X-Received: by 2002:a05:600c:4f92:b0:426:6e8b:3dc5 with SMTP id 5b1f17b1804b1-428e6b92636mr114329335e9.32.1722934977720; Tue, 06 Aug 2024 02:02:57 -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 5b1f17b1804b1-428e6e03c4csm173461085e9.13.2024.08.06.02.02.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Aug 2024 02:02:57 -0700 (PDT) From: =?utf-8?q?Marc_Poulhi=C3=A8s?= To: gcc-patches@gcc.gnu.org Cc: Javier Miranda Subject: [COMMITTED 6/9] ada: Spurious error on the default value of a derived scalar type Date: Tue, 6 Aug 2024 11:02:38 +0200 Message-ID: <20240806090241.576862-6-poulhies@adacore.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240806090241.576862-1-poulhies@adacore.com> References: <20240806090241.576862-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 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: Javier Miranda When the aspect Default_Value is inherited by a derived scalar type, and both the parent type T and the derived type DT are declared in the same scope, a spurious error may be reported. This occurs if a subprogram declared in the same scope has a parameter of type DT with a default value, leading the compiler to incorrectly flag the default value specified in the aspect of type T as having the wrong type. gcc/ada/ * freeze.adb (Freeze_Entity): For scalar derived types that inherit the aspect Default_Value, do not analyze and resolve the inherited aspect, as the type of the aspect remains the parent type. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/freeze.adb | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/gcc/ada/freeze.adb b/gcc/ada/freeze.adb index a947018052c..7d5be6b6744 100644 --- a/gcc/ada/freeze.adb +++ b/gcc/ada/freeze.adb @@ -7820,7 +7820,24 @@ package body Freeze is -- type itself, and we treat Default_Component_Value similarly for -- the sake of uniformity). - if Is_First_Subtype (E) and then Has_Default_Aspect (E) then + -- But for an inherited Default_Value aspect specification, the type + -- of the aspect remains the parent type. RM 3.3.1(11.1), a dynamic + -- semantics rule, says "The implicit initial value for a scalar + -- subtype that has the Default_Value aspect specified is the value + -- of that aspect converted to the nominal subtype". For an inherited + -- Default_Value aspect specification, no conversion is evaluated at + -- the point of the derived type declaration. + + if Is_First_Subtype (E) + and then Has_Default_Aspect (E) + and then + (not Is_Scalar_Type (E) + or else + not Is_Derived_Type (E) + or else + Default_Aspect_Value (E) + /= Default_Aspect_Value (Etype (Base_Type (E)))) + then declare Nam : Name_Id; Exp : Node_Id;