From patchwork Fri Jan 7 16:26:58 2022 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: 49699 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 31E803857C6A for ; Fri, 7 Jan 2022 16:32:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 31E803857C6A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1641573147; bh=DKm2GaIvOL3wvt4n3KPDMdCXvf/TvJtbU5pkFQ73Lxc=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=DIWJllQWMpmSMMvFybplTripEF3rkABuNvF5ZvH9nvGti8JzpWRr2A7MIONTkLiwK QJiMfqO3MZZ/t9XlubbPY2NhHLgusUkkVBDzCN0xsLu8u13S9LVgcM+aP8AXtLAMhy +if5oK/7Fon2U699l3xFoqwQ6DO6aiNkrYkUJ/aU= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by sourceware.org (Postfix) with ESMTPS id C0CE03858421 for ; Fri, 7 Jan 2022 16:27:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C0CE03858421 Received: by mail-wm1-x32b.google.com with SMTP id l4so4277646wmq.3 for ; Fri, 07 Jan 2022 08:27:00 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition; bh=DKm2GaIvOL3wvt4n3KPDMdCXvf/TvJtbU5pkFQ73Lxc=; b=AboYLiEWFGZifuOuMCPiV35GXzgwzFVwp/O9xsuPAeEpPmkNn7TJGr/9rfkvVXR2/X 15HcsvZp0+1OpU9liUGVEGe6xdsei3OFaVlCeZcXUfsRtv2NsGG1oEUFpB+mL6bpCGOo iWt5DDAv4BpyeiZJKPsH6kFcFoiIlJqFqHST7l50aK4l6iARp6AZcs48ucCUenwoP+UQ BX3bAMgR5JgBCTgekZwDkMadaCLd3rpocKwyMiRtR4lHDJWDc+7SMckmjYmN5QZRnvtR D+OThBvAXZLjeikfogZXfY0YSFlR2t8W+LEzWnA1eTuVp9Llr5zRP0x0Of6HcCCd06Up IlqA== X-Gm-Message-State: AOAM531APFRSfApswPcyYz0gSYE0yI/8NILTWkDc9eWVlleUc4IVWOdc EDp7kLFjvsaXb2JIzEB5pb24GyhIMWhpjw== X-Google-Smtp-Source: ABdhPJxy6efJGXyM0En36XtubFgX2ihNd1gSxpe3MGqD1VCzZMUVpiTKtCsIP1WSo2Y+o/FkoR2hVg== X-Received: by 2002:a05:600c:3b0f:: with SMTP id m15mr5117744wms.4.1641572819832; Fri, 07 Jan 2022 08:26:59 -0800 (PST) Received: from adacore.com ([45.147.211.82]) by smtp.gmail.com with ESMTPSA id m6sm1122697wrx.36.2022.01.07.08.26.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Jan 2022 08:26:59 -0800 (PST) Date: Fri, 7 Jan 2022 16:26:58 +0000 To: gcc-patches@gcc.gnu.org Subject: [Ada] Use non-internal representation for access subprograms if UC to Address Message-ID: <20220107162658.GA948113@adacore.com> MIME-Version: 1.0 Content-Disposition: inline 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, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: Pierre-Marie de Rodat via Gcc-patches From: Pierre-Marie de Rodat Reply-To: Pierre-Marie de Rodat Cc: Richard Kenner Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" If we have an Unchecked_Conversion between an access to subprogram and System.Address, we want to try to use a thin subprogram pointer. Try to do this automatically as much as possible and add one to the RTS. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * libgnat/g-spipat.ads (Boolean_Func, Natural_Func, VString_Func): Mark as Favor_Top_Level. * sem_ch13.adb (Validate_Unchecked_Conversion): Avoid using internal representation if Unchecked_Conversion between an access to subprogram and System.Address within the same unit. diff --git a/gcc/ada/libgnat/g-spipat.ads b/gcc/ada/libgnat/g-spipat.ads --- a/gcc/ada/libgnat/g-spipat.ads +++ b/gcc/ada/libgnat/g-spipat.ads @@ -654,19 +654,19 @@ package GNAT.Spitbol.Patterns is -- operations for constructing patterns that can be used in the pattern -- matching operations provided. - type Boolean_Func is access function return Boolean; + type Boolean_Func is access function return Boolean with Favor_Top_Level; -- General Boolean function type. When this type is used as a formal -- parameter type in this package, it indicates a deferred predicate -- pattern. The function will be called when the pattern element is -- matched and failure signalled if False is returned. - type Natural_Func is access function return Natural; + type Natural_Func is access function return Natural with Favor_Top_Level; -- General Natural function type. When this type is used as a formal -- parameter type in this package, it indicates a deferred pattern. -- The function will be called when the pattern element is matched -- to obtain the currently referenced Natural value. - type VString_Func is access function return VString; + type VString_Func is access function return VString with Favor_Top_Level; -- General VString function type. When this type is used as a formal -- parameter type in this package, it indicates a deferred pattern. -- The function will be called when the pattern element is matched 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 @@ -17546,6 +17546,22 @@ package body Sem_Ch13 is Set_No_Strict_Aliasing (Implementation_Base_Type (Target)); end if; + -- If the unchecked conversion is between Address and an access + -- subprogram type, show that we shouldn't use an internal + -- representation for the access subprogram type. + + if Is_Access_Subprogram_Type (Target) + and then Is_Descendant_Of_Address (Source) + and then In_Same_Source_Unit (Target, N) + then + Set_Can_Use_Internal_Rep (Target, False); + elsif Is_Access_Subprogram_Type (Source) + and then Is_Descendant_Of_Address (Target) + and then In_Same_Source_Unit (Source, N) + then + Set_Can_Use_Internal_Rep (Source, False); + end if; + -- Generate N_Validate_Unchecked_Conversion node for back end in case -- the back end needs to perform special validation checks.