From patchwork Tue May 16 08:41:15 2023 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: 94525 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp272260vqo; Tue, 16 May 2023 01:47:05 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7mReqN8fu9JReIL45EHiHj5fInX2lbo2ZM4EP/m/RMUtuH0VigxbVGk2gjKWL5Qr89ALbQ X-Received: by 2002:aa7:c3c6:0:b0:50b:df56:8d68 with SMTP id l6-20020aa7c3c6000000b0050bdf568d68mr25301111edr.9.1684226825681; Tue, 16 May 2023 01:47:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684226825; cv=none; d=google.com; s=arc-20160816; b=rQl7rSqZ+Rnv2mLfSuhIvF8XYVglZwITyPzz5jAVG88IHvI1CHoVmXJrHEoQrP1a+h xA2kynkpmp0k5H4o7mCvcw67gmdCWYbZe97x7k64SO47gbBPlZDoY+z2hnjhhOlTKOQV 0WVdzcDmRzeS3PRdQ50ksjbNUk/VlEvxhEFoJNWBPnoeuMJm7rBdGCpu82QiIrur3uWp yk8RLgyUR4/U+kY/BlLUCb8lO+cE+HR8/ax3Y5DlDF99uVkApYg9wWq17FEN4OhO3rfl rUdZMZEr3+PGdY4Agx6NNmE5aVtWYe1f66Vh4WK3alOJBmGNMsTEgJqu1lkta1oyZpCy KYDg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:cc :to:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=F7CV7aTgs6RjHtGxGDe7HeWvSVfd15mqYupIOLpjxVI=; b=qvljbvX82Alw9WFXdNbgSrubGCRQbVfKrx6HLg8Vy2ojS7iF2qowYilx8omS2OCeq3 suuFS3DACPX9Qrb/76+sbQwuDX6jp1XXHphHgytJZcR/86xcBIQBxBUm9s7NRe4JbOaY dr9T6SdmVykxied6D8EH2XI9ZIDvMjJlfEoW01/S4L9wv32TLlW5TyN0yoFigAYLj7iF IFhxw41RiMdohbrXDu6KPFnRUHE1u6ihHDTDDruoUENwxG4aW1zTb9CBXoxkSn3/QCKW acHC0qialBdcQrSSIhkJCRb36GkILLLPYReusZ5PPbbM/pGAsGlaPbCKND1ZHaKa98VQ njcg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=jt5WW303; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id r7-20020a056402018700b005067c959debsi12355007edv.603.2023.05.16.01.47.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 May 2023 01:47:05 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=jt5WW303; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 796713881D06 for ; Tue, 16 May 2023 08:43:24 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 796713881D06 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1684226604; bh=F7CV7aTgs6RjHtGxGDe7HeWvSVfd15mqYupIOLpjxVI=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=jt5WW303nmlwSCwX8msIJq5UDDsWAssLWLZ7qhbivPHxSq71M+BpGpEAM5eF7tBRC 7AvLtKcvu8meIRgne1NNEG4qBbUSgY97N9M9vbeTaaYhqpn+tQ1PtxOkeuIKr9BBzd IqqsDXCIwSTSWcQp8gERdEZ0gGbiIhVlOfatiGBU= 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 065753854176 for ; Tue, 16 May 2023 08:41:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 065753854176 Received: by mail-wr1-x429.google.com with SMTP id ffacd0b85a97d-3063891d61aso13170741f8f.0 for ; Tue, 16 May 2023 01:41:18 -0700 (PDT) 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-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) 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 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 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: , X-Patchwork-Original-From: =?utf-8?q?Marc_Poulhi=C3=A8s_via_Gcc-patches?= From: =?utf-8?q?Marc_Poulhi=C3=A8s?= Reply-To: =?utf-8?q?Marc_Poulhi=C3=A8s?= Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766039827737687055?= X-GMAIL-MSGID: =?utf-8?q?1766039827737687055?= 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.