From patchwork Mon Jul 6 11:38:54 2020 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: 1323553 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=adacore.com Received: from 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 RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4B0k9s6XmJz9sQt for ; Mon, 6 Jul 2020 21:39:13 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3FF84385700C; Mon, 6 Jul 2020 11:38:58 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from rock.gnat.com (rock.gnat.com [IPv6:2620:20:4000:0:a9e:1ff:fe9b:1d1]) by sourceware.org (Postfix) with ESMTP id 181233857C6B for ; Mon, 6 Jul 2020 11:38:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 181233857C6B Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=derodat@adacore.com Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id E90A25603C; Mon, 6 Jul 2020 07:38:54 -0400 (EDT) X-Virus-Scanned: Debian amavisd-new at gnat.com Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id IhqzeLbRjOG4; Mon, 6 Jul 2020 07:38:54 -0400 (EDT) Received: from tron.gnat.com (tron.gnat.com [IPv6:2620:20:4000:0:46a8:42ff:fe0e:e294]) by rock.gnat.com (Postfix) with ESMTP id D60C05603A; Mon, 6 Jul 2020 07:38:54 -0400 (EDT) Received: by tron.gnat.com (Postfix, from userid 4862) id D54A1E9; Mon, 6 Jul 2020 07:38:54 -0400 (EDT) Date: Mon, 6 Jul 2020 07:38:54 -0400 From: Pierre-Marie de Rodat To: gcc-patches@gcc.gnu.org Subject: [Ada] AI12-0376 Relax RM 13.1(10) rule wrt primitive operations Message-ID: <20200706113854.GA135418@adacore.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: Arnaud Charlet Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" After discussions at the ARG, the rule in RM 13.1(10) limiting representation aspects on derived types is removed by AI12-0376. It has also been confirmed that Default_Component_Value is a representation aspect. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * aspects.ads (Is_Representation_Aspect): Default_Component_Value is a representation aspect. * sem_ch13.adb (Check_Aspect_Too_Late, Rep_Item_Too_Late): Relax RM 13.1(10) rule wrt primitive operations for Ada 202x. diff --git a/gcc/ada/aspects.ads b/gcc/ada/aspects.ads --- a/gcc/ada/aspects.ads +++ b/gcc/ada/aspects.ads @@ -454,7 +454,7 @@ package Aspects is Aspect_Contract_Cases => False, Aspect_Convention => True, Aspect_CPU => False, - Aspect_Default_Component_Value => False, + Aspect_Default_Component_Value => True, Aspect_Default_Initial_Condition => False, Aspect_Default_Iterator => False, Aspect_Default_Storage_Pool => True, diff --git a/gcc/ada/sem_ch13.adb b/gcc/ada/sem_ch13.adb --- a/gcc/ada/sem_ch13.adb +++ b/gcc/ada/sem_ch13.adb @@ -952,7 +952,6 @@ package body Sem_Ch13 is procedure Check_Aspect_Too_Late (N : Node_Id) is Typ : constant Entity_Id := Entity (N); Expr : constant Node_Id := Expression (N); - A_Id : constant Aspect_Id := Get_Aspect_Id (N); function Find_Type_Reference (Typ : Entity_Id; Expr : Node_Id) return Boolean; @@ -995,42 +994,44 @@ package body Sem_Ch13 is Parent_Type : Entity_Id; begin - if A_Id /= Aspect_Default_Value then + -- Ensure Expr is analyzed so that e.g. all types are properly + -- resolved for Find_Type_Reference. - -- Ensure Expr is analyzed so that e.g. all types are properly - -- resolved for Find_Type_Reference. - - Analyze (Expr); + Analyze (Expr); - -- A self-referential aspect is illegal if it forces freezing the - -- entity before the corresponding aspect has been analyzed. + -- A self-referential aspect is illegal if it forces freezing the + -- entity before the corresponding aspect has been analyzed. - if Find_Type_Reference (Typ, Expr) then - Error_Msg_NE - ("aspect specification causes premature freezing of&", - N, Typ); - end if; + if Find_Type_Reference (Typ, Expr) then + Error_Msg_NE + ("aspect specification causes premature freezing of&", N, Typ); end if; -- For representation aspects, check for case of untagged derived - -- type whose parent either has primitive operations, or is a by - -- reference type (RM 13.1(10)). + -- type whose parent either has primitive operations (pre Ada 202x), + -- or is a by-reference type (RM 13.1(10)). + -- Strictly speaking the check also applies to Ada 2012 but it is + -- really too constraining for existing code already, so relax it. + -- ??? Confirming aspects should be allowed here. - if Is_Representation_Aspect (A_Id) + if Is_Representation_Aspect (Get_Aspect_Id (N)) and then Is_Derived_Type (Typ) and then not Is_Tagged_Type (Typ) then Parent_Type := Etype (Base_Type (Typ)); - if Has_Primitive_Operations (Parent_Type) then - No_Type_Rep_Item (N); + if Ada_Version <= Ada_2012 + and then Has_Primitive_Operations (Parent_Type) + then + Error_Msg_N + ("|representation aspect not permitted before Ada 202x!", N); Error_Msg_NE ("\parent type & has primitive operations!", N, Parent_Type); elsif Is_By_Reference_Type (Parent_Type) then No_Type_Rep_Item (N); Error_Msg_NE - ("\parent type & is a by reference type!", N, Parent_Type); + ("\parent type & is a by-reference type!", N, Parent_Type); end if; end if; end Check_Aspect_Too_Late; @@ -13868,9 +13869,11 @@ package body Sem_Ch13 is return True; -- Check for case of untagged derived type whose parent either has - -- primitive operations, or is a by reference type (RM 13.1(10)). In - -- this case we do not output a Too_Late message, since there is no - -- earlier point where the rep item could be placed to make it legal. + -- primitive operations (pre Ada 202x), or is a by-reference type (RM + -- 13.1(10)). In this case we do not output a Too_Late message, since + -- there is no earlier point where the rep item could be placed to make + -- it legal. + -- ??? Confirming representation clauses should be allowed here. elsif Is_Type (T) and then not FOnly @@ -13879,24 +13882,22 @@ package body Sem_Ch13 is then Parent_Type := Etype (Base_Type (T)); - if Has_Primitive_Operations (Parent_Type) then - No_Type_Rep_Item (N); - - if not Relaxed_RM_Semantics then - Error_Msg_NE - ("\parent type & has primitive operations!", N, Parent_Type); - end if; + if Relaxed_RM_Semantics then + null; + elsif Ada_Version <= Ada_2012 + and then Has_Primitive_Operations (Parent_Type) + then + Error_Msg_N + ("|representation item not permitted before Ada 202x!", N); + Error_Msg_NE + ("\parent type & has primitive operations!", N, Parent_Type); return True; elsif Is_By_Reference_Type (Parent_Type) then No_Type_Rep_Item (N); - - if not Relaxed_RM_Semantics then - Error_Msg_NE - ("\parent type & is a by reference type!", N, Parent_Type); - end if; - + Error_Msg_NE + ("\parent type & is a by-reference type!", N, Parent_Type); return True; end if; end if;