From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 065753854176 for ; Tue, 16 May 2023 08:41:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 065753854176 Authentication-Results: sourceware.org; dmarc=pass (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 ffacd0b85a97d-3063891d61aso13170741f8f.0 for ; Tue, 16 May 2023 01:41:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1684226478; x=1686818478; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=F7CV7aTgs6RjHtGxGDe7HeWvSVfd15mqYupIOLpjxVI=; b=UxEnTGcRg7F5sll8dRu68PA7z6UAKZz8MlnoJgJPYZWSz1HgYua/GyTve0TaBxn4EL f4oEPyVRUKYZ+Z2ZR0y0lQ9cDgK/2TcrgyH1RZG0KGQvKOmGXlagaC9X4BTkTHVTZmPr zE5SoJl/JU7OXZ1RAayEpXwbCvnBAv6BUjzCqZKzbnF4yuD1LaXuwEnX0f7MIN9Rn0t4 5jpxK4QZU/SNnpbmMHyWpK09SFv5MIV4wOuvONTZNwiRgm+zAajwAGyI7c3pLmsIaLCh bfJpNVPGvZgHke6VJ5sYKn9E4i5KR5Zzt3dvM8qE2RtXz5/Pqp35xpwf5rRCAwRmAcJf xiyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684226478; x=1686818478; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=F7CV7aTgs6RjHtGxGDe7HeWvSVfd15mqYupIOLpjxVI=; b=JZQXNiwwheTRYw5v77hJ3yMeASxNYJ+H898Gf3/iortVX3Uumvye4E9UJqayMvG+Pw G1nc5B4c4+aXDPndKWIQDAc8YbXr8Pvs4y1J2s1KnWMjR0qssKLDuMY7mlsPub9qf3h5 fgttnbOJ0De3VQ+19CVO5pqnkx12dYj4CKy3tCm+vmM/kb5y85QwTuAMnsQ+SKKqn+EW 2a8xL25ZF0SAwq91P0+NgHLZLcIE+jj0UxSOwejtit3Le4pDwDOUppP3HpI4ytUp5SQ4 o6DKh4fLkdUzi7dY6SBl6biZf7HyU5ljoyBJYUEGP2tgefLnfz1eBVkQnEmABxMFMHkE qCKQ== X-Gm-Message-State: AC+VfDzhsuLUmvRV8ikyOAcqB1+uGmCwzHn2DelrfyWXd7ycjaT8u9vZ n/9AmkAN6dET3V5xqN1VOVl8a9Nsd0AYlAayqSgDaA== X-Google-Smtp-Source: ACHHUZ5rOO6snSmUUT+s4jU5xlw6d6U0DwoYyO8Ub0gcb554MU28UwT5IxCe5mh/lxi3pHIpMB9n5g== X-Received: by 2002:adf:df0c:0:b0:2f9:cee4:b7d with SMTP id y12-20020adfdf0c000000b002f9cee40b7dmr22748096wrl.70.1684226477689; Tue, 16 May 2023 01:41:17 -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 x8-20020a05600c21c800b003f4f8cc4285sm1524267wmj.17.2023.05.16.01.41.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 May 2023 01:41:17 -0700 (PDT) From: =?UTF-8?q?Marc=20Poulhi=C3=A8s?= To: gcc-patches@gcc.gnu.org Cc: Eric Botcazou Subject: [COMMITTED] ada: Implement inheritance of user-defined literal aspects for untagged types Date: Tue, 16 May 2023 10:41:15 +0200 Message-Id: <20230516084115.1502135-1-poulhies@adacore.com> X-Mailer: git-send-email 2.40.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-13.1 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_ASCII_DIVIDERS,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 List-Id: From: Eric Botcazou In Ada 2022, user-defined literal aspects are nonoverridable but the named subprograms present in them can be overridden, including for untagged types. gcc/ada/ * sem_res.adb (Has_Applicable_User_Defined_Literal): Apply the same processing for derived untagged types as for tagged types. * sem_util.ads (Corresponding_Primitive_Op): Adjust description. * sem_util.adb (Corresponding_Primitive_Op): Handle untagged types. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/sem_res.adb | 1 - gcc/ada/sem_util.adb | 39 +++++++++++++++++++++++++++++++++++---- gcc/ada/sem_util.ads | 6 +++--- 3 files changed, 38 insertions(+), 8 deletions(-) diff --git a/gcc/ada/sem_res.adb b/gcc/ada/sem_res.adb index df9ccb18468..f6634da42a7 100644 --- a/gcc/ada/sem_res.adb +++ b/gcc/ada/sem_res.adb @@ -492,7 +492,6 @@ package body Sem_Res is Name := Make_Identifier (Loc, Chars (Callee)); if Is_Derived_Type (Typ) - and then Is_Tagged_Type (Typ) and then Base_Type (Etype (Callee)) /= Base_Type (Typ) then Callee := diff --git a/gcc/ada/sem_util.adb b/gcc/ada/sem_util.adb index 38dc654f7be..1d8d4fc30f8 100644 --- a/gcc/ada/sem_util.adb +++ b/gcc/ada/sem_util.adb @@ -6483,9 +6483,8 @@ package body Sem_Util is (Ancestor_Op : Entity_Id; Descendant_Type : Entity_Id) return Entity_Id is - Typ : constant Entity_Id := Find_Dispatching_Type (Ancestor_Op); - Elmt : Elmt_Id; - Subp : Entity_Id; + function Find_Untagged_Type_Of (Prim : Entity_Id) return Entity_Id; + -- Search for the untagged type of the primitive operation Prim. function Profile_Matches_Ancestor (S : Entity_Id) return Boolean; -- Returns True if subprogram S has the proper profile for an @@ -6493,6 +6492,34 @@ package body Sem_Util is -- have the same type, or are corresponding controlling formals, -- and similarly for result types). + --------------------------- + -- Find_Untagged_Type_Of -- + --------------------------- + + function Find_Untagged_Type_Of (Prim : Entity_Id) return Entity_Id is + E : Entity_Id := First_Entity (Scope (Prim)); + + begin + while Present (E) and then E /= Prim loop + if not Is_Tagged_Type (E) + and then Present (Direct_Primitive_Operations (E)) + and then Contains (Direct_Primitive_Operations (E), Prim) + then + return E; + end if; + + Next_Entity (E); + end loop; + + pragma Assert (False); + return Empty; + end Find_Untagged_Type_Of; + + Typ : constant Entity_Id := + (if Is_Dispatching_Operation (Ancestor_Op) + then Find_Dispatching_Type (Ancestor_Op) + else Find_Untagged_Type_Of (Ancestor_Op)); + ------------------------------ -- Profile_Matches_Ancestor -- ------------------------------ @@ -6529,10 +6556,14 @@ package body Sem_Util is or else Is_Ancestor (Typ, Etype (S))); end Profile_Matches_Ancestor; + -- Local variables + + Elmt : Elmt_Id; + Subp : Entity_Id; + -- Start of processing for Corresponding_Primitive_Op begin - pragma Assert (Is_Dispatching_Operation (Ancestor_Op)); pragma Assert (Is_Ancestor (Typ, Descendant_Type) or else Is_Progenitor (Typ, Descendant_Type)); diff --git a/gcc/ada/sem_util.ads b/gcc/ada/sem_util.ads index f98e05615fd..42c6d249e2f 100644 --- a/gcc/ada/sem_util.ads +++ b/gcc/ada/sem_util.ads @@ -618,9 +618,9 @@ package Sem_Util is -- Possible optimization??? function Corresponding_Primitive_Op - (Ancestor_Op : Entity_Id; - Descendant_Type : Entity_Id) return Entity_Id; - -- Given a primitive subprogram of a tagged type and a (distinct) + (Ancestor_Op : Entity_Id; + Descendant_Type : Entity_Id) return Entity_Id; + -- Given a primitive subprogram of a first type and a (distinct) -- descendant type of that type, find the corresponding primitive -- subprogram of the descendant type. -- 2.40.0