From patchwork Thu Aug 8 14:29:48 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: 1970585 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=Q88/XDC5; 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 4WfqJ53bCLz1ybS for ; Fri, 9 Aug 2024 00:32:21 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A1BEC3861034 for ; Thu, 8 Aug 2024 14:32:19 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by sourceware.org (Postfix) with ESMTPS id D8A2D386103C for ; Thu, 8 Aug 2024 14:30:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D8A2D386103C 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 D8A2D386103C Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::333 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1723127443; cv=none; b=gbZu2thnLU40/sfvv53mn2oiR0M8XdYTAgyPD6NpSWWUeQCWF7LbfomWX/Bvp92Sjg+nQjdg/04KKSHZWvnKvuBYEgVdSSWqhVu/jq2D93oyZVS/u28sGERaugvBg5I/ZX7z0QfKcGdo8KYmTTUvhdWub1U7bKyp39hcURl1fIk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1723127443; c=relaxed/simple; bh=mTinstReLXFDfH2GQyeqbsSJLtWMSiH2tuA8B5ux6xA=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=Muy94OS+cqS8tMo/8HVobhf4qU6E32fRryTE1sGhcb7UTaubj76SCQ7CYwNFdeCvBjsjaXD6Q6x0l7LrO2d9ozTufimf/fl09qdWn+yWFAFmP4tHRhNjcTS/WrcgZZB+4BErhCxSlFGFKzxsl5r6fVPeawon0fiPZzVWY+V8yfU= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-428243f928fso10670985e9.0 for ; Thu, 08 Aug 2024 07:30:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1723127438; x=1723732238; 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=JAHi+yWG/iRa83L3xUKLJq0W/LFvbEPTiewMYbLOkZY=; b=Q88/XDC5kiDnsTPJmI2AAEl0fA8hn4swWYMmXO7Td5Tdy7gtdGwDT+3fuvPs/nxU0/ K5UUNbyDl13SpZtrwuGpcT6ZrouEBaEkDIL9vwSmY53uonAwDN0luOUh8NtVHOv1NfLB cHF9gnquusEGwcXDjOlbpDlMnbvVlgHq3mQRDfLFcd9H0DSYErp9rx+DMpLNmKA1mt5i +RMQafs5Xdfd0gMk0DdLtksDnMhCz5TzZpUf8yYwpgXrq11uC/mE4YB7SMTTW4Z0ID4Z ym8TtNf2Vlnt3foYLWwUz/Oxs0kRpmcJrmosi5G+vMKddOwQJMKMLmK/0DwXTZPCyeMB rXHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723127438; x=1723732238; 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=JAHi+yWG/iRa83L3xUKLJq0W/LFvbEPTiewMYbLOkZY=; b=QKnpXGA0WB6jWoSkjCnrHUILPQ4EIgn60AX/gsGzSvjqXNaDlLEiDYZDbVZKdCTHB4 Sw5CHHQkN7byxLJWyRrMtuUSIGUbLqT+qONphsSCo/r0LRazP2KBWLic0uSh2nJEm3vH Wiy17B33iePG+wfPOu+SoDrn+2SycR1BZebCCtK0Y2HzccBKsqYjjTvTeEfgD1RPdcC2 SNF+9aYNfQcZxS3swfFYJRvjliVE6MJHcBu5YbJuCtLQZWK8XNK3lMmwEo1nv0NBdf0x p04xG3vAQAReJdF0UvWZr8xWMe6/QjStyy6VWZt6Rig4FTEJI/xREInzFrTQyiklLD1g d+qg== X-Gm-Message-State: AOJu0Yw+mFjhB1LrNlOLT4XvJwdBPpXQWJ9g1rESMSzfYTb3oGszT78J vgqmRpKioEw5lowL5NJiDLunvq04yfOEQsTLxBmsy75ot20OhIvAFAexLMLRY4WdwMqnVyoub8/ I3A== X-Google-Smtp-Source: AGHT+IHNFgf7WM0bca8NjVxhogAeDIFbLHl14pkElvlbSIb89NTUZl3VyOp6v9DaxwIkWt0AppvsLQ== X-Received: by 2002:a05:600c:4f55:b0:426:6f87:65fc with SMTP id 5b1f17b1804b1-4290af072a1mr20228755e9.17.1723127438403; Thu, 08 Aug 2024 07:30:38 -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-4290c72d6c8sm25992015e9.9.2024.08.08.07.30.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Aug 2024 07:30:37 -0700 (PDT) From: =?utf-8?q?Marc_Poulhi=C3=A8s?= To: gcc-patches@gcc.gnu.org Cc: Steve Baird Subject: [COMMITTED 6/6] ada: Missing legality check when type completed Date: Thu, 8 Aug 2024 16:29:48 +0200 Message-ID: <20240808142948.807190-6-poulhies@adacore.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240808142948.807190-1-poulhies@adacore.com> References: <20240808142948.807190-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: Steve Baird An access discriminant is allowed to have a default value only if the discriminated type is immutably limited. In the case of a discriminated limited private type declaration, this rule needs to be checked when the completion of the type is seen. gcc/ada/ * sem_ch6.adb (Check_Discriminant_Conformance): Perform check for illegal access discriminant default values when the completion of a limited private type is analyzed. * sem_aux.adb (Is_Immutably_Limited): If passed the not-yet-analyzed entity for the full view of a record type, test the Limited_Present flag (which is set by the parser). Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/sem_aux.adb | 11 +++++++++++ gcc/ada/sem_ch6.adb | 14 ++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/gcc/ada/sem_aux.adb b/gcc/ada/sem_aux.adb index 0639a2e4d86..9903a2b6a16 100644 --- a/gcc/ada/sem_aux.adb +++ b/gcc/ada/sem_aux.adb @@ -1118,6 +1118,17 @@ package body Sem_Aux is elsif Is_Private_Type (Btype) then + -- If Ent occurs in the completion of a limited private type, then + -- look for the word "limited" in the full view. + + if Nkind (Parent (Ent)) = N_Full_Type_Declaration + and then Nkind (Type_Definition (Parent (Ent))) = + N_Record_Definition + and then Limited_Present (Type_Definition (Parent (Ent))) + then + return True; + end if; + -- AI05-0063: A type derived from a limited private formal type is -- not immutably limited in a generic body. diff --git a/gcc/ada/sem_ch6.adb b/gcc/ada/sem_ch6.adb index d3912ffc9d5..5735efb327c 100644 --- a/gcc/ada/sem_ch6.adb +++ b/gcc/ada/sem_ch6.adb @@ -6456,6 +6456,20 @@ package body Sem_Ch6 is New_Discr_Id); return; end if; + + if NewD + and then Ada_Version >= Ada_2005 + and then Nkind (Discriminant_Type (New_Discr)) = + N_Access_Definition + and then not Is_Immutably_Limited_Type + (Defining_Identifier (N)) + then + Error_Msg_N + ("(Ada 2005) default value for access discriminant " + & "requires immutably limited type", + Expression (New_Discr)); + return; + end if; end if; end;