From patchwork Tue Jan 3 09:35:49 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: 38336 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp4524841wrt; Tue, 3 Jan 2023 01:40:09 -0800 (PST) X-Google-Smtp-Source: AMrXdXsGUKibCU+eVIW9WPOX0aqkfa/mPPsl3QvHXOsahQp8DAMxMIUnIzNvaC8/VoMMxEvvz/ie X-Received: by 2002:a17:906:9be4:b0:7c0:e99a:e353 with SMTP id de36-20020a1709069be400b007c0e99ae353mr33603920ejc.56.1672738809233; Tue, 03 Jan 2023 01:40:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672738809; cv=none; d=google.com; s=arc-20160816; b=JAmYTSZ8tZyG3dOXzbkyiPsB0ou09d1ffb7MwnVheJVMKvfcojq7zGWVE8yNy1uK1S usH1ouvlZk6y8QQtLQJoXRl9q5IxZo7+zcfseR6kVySHARtXpEFX96xh4u8DyfTGuTt8 iVk5kJR4nvsvIb8QzrL6K+Vwd3tA/mBMICd8fI/LnK8csvt+Y5rbHaWsBolSzwXdfVcY xZi4SbwghDa2Ssd9JDYRxZWmTxrQwh1JOqPtEvik/ODMEKx5szq0wPaLwJnBlWnIBrNp //W5n6drMLaAPJn23RPqPJQLFYkH+hD2QFgcWAEwbKydhAIAzS3FiDShUiFEHQf46gLI ce7g== 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:delivered-to:dkim-signature:dkim-filter; bh=8ykrPzRhb5RpgGalp4GUOjWXIdz6nQs6Cz2m2gKYY7Q=; b=QTR7xJ+TpkM3KzofgTNGqVl9VgoFE8iMmHzE06eT0JykeULzalZ7izpufBieISCUle x0lZtNBKdNZm/HjPwlvaDme15Y+PpEXg+qqhO6XP9QymUZpWx2hcLDnGuUWAe5pxhcW+ OMZoWeszfkdAeo80WZYdNKZVVYSpviiEVptZ4DTmVEjsSUVwk+a4rmwt5XB1TCjF0vVg h6mW4JNSGIICh7HxjrKYAabZ4dfCyo5qeHBuc9bT6ZC3QISBMozUiIjU3bo/QfUTamJs og5R9gFTEqayXckkIPDDUYAp9qsGq8B6Vu/rGjyCkfAlbdib4dA+AxTW3FtfhJFCt8jG 4jJw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=hLJ7aPtd; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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. [8.43.85.97]) by mx.google.com with ESMTPS id ht10-20020a170907608a00b007c0a516af79si28197845ejc.313.2023.01.03.01.40.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Jan 2023 01:40:09 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=hLJ7aPtd; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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 284913895FD1 for ; Tue, 3 Jan 2023 09:37:56 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 284913895FD1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1672738676; bh=8ykrPzRhb5RpgGalp4GUOjWXIdz6nQs6Cz2m2gKYY7Q=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=hLJ7aPtdj20S8Zmv/MRC9RS37F33L4hGAY8YFcHrmZKbFOYlk6Q+WWZk8DT1mOH5+ ccyG1emEma8ivuHCL70BsMUK0cADySsLGd6giUGRfOfD2qeq4j0GH5SgAkLQ22A/Gh R+fkn1kQiVeuBGmvxqA2cColYU1Z4SPBa6fVAQbI= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) by sourceware.org (Postfix) with ESMTPS id 5611C385B535 for ; Tue, 3 Jan 2023 09:35:53 +0000 (GMT) Received: by mail-wm1-x332.google.com with SMTP id bg13-20020a05600c3c8d00b003d9712b29d2so20124499wmb.2 for ; Tue, 03 Jan 2023 01:35:53 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=8ykrPzRhb5RpgGalp4GUOjWXIdz6nQs6Cz2m2gKYY7Q=; b=A1sSts27b3zHTZQi1n2eurBbDo3Ej9kbV8CyewtA+ep/yl5ehTjLe+smiIraJnQMRZ yiyYAXMxS8rcLQi48yJddnc6NZ3HdP26fyRbFmOMTwTBap4u128W5p9YvRzRU7u1OlOl rsTDCJIXG3cnQh/Eaux0eteQQqoLcHljmGfkKoOIfsgSMzoeHn3YAvV6es1HgO9wzYF2 ImHdlj+k8vXbLw/LhPNDxfehg5TEoKgc1Azqr9bQRAJmhJ/q3YzhSwYmcSWZdARRT6/5 kZkZ90JZWIVZuilxTri6sVh1sEYG/RBm1FMVxH1uOk0moJEuOtt6Pqr9OfLBAukT/qom 7+Ew== X-Gm-Message-State: AFqh2kprm9QBg3dVh7xYTs6r4xTxXeG/mCleejbJlzuCjgEt4co4hOH/ vWA9bApzNOgCG4rfZilorIkzzaTA4Av8JZMx9ZE= X-Received: by 2002:a1c:4b14:0:b0:3d3:5ade:4317 with SMTP id y20-20020a1c4b14000000b003d35ade4317mr29977340wma.8.1672738552204; Tue, 03 Jan 2023 01:35:52 -0800 (PST) Received: from localhost.localdomain (static-176-191-105-132.ftth.abo.bbox.fr. [176.191.105.132]) by smtp.gmail.com with ESMTPSA id i17-20020a05600c355100b003d9980c5e7asm22347197wmq.21.2023.01.03.01.35.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Jan 2023 01:35:51 -0800 (PST) To: gcc-patches@gcc.gnu.org Cc: Eric Botcazou Subject: [COMMITTED] ada: Fix calling convention of foreign functions returning limited type Date: Tue, 3 Jan 2023 10:35:49 +0100 Message-Id: <20230103093549.76562-1-poulhies@adacore.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Spam-Status: No, score=-13.5 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.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?1753993769511440647?= X-GMAIL-MSGID: =?utf-8?q?1753993769511440647?= From: Eric Botcazou Such functions use neither Ada 2005's build-in-place mechanism nor Ada 95's return-by-reference mechanism, but instead the common calling convention of functions returning a nonlimited by-reference type. gcc/ada/ * exp_ch6.adb (Is_Build_In_Place_Function): Adjust comment. * sem_util.adb (Compute_Returns_By_Ref): Do not set Returns_By_Ref on functions with foreign convention. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/exp_ch6.adb | 8 ++++---- gcc/ada/sem_util.adb | 7 +++++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/gcc/ada/exp_ch6.adb b/gcc/ada/exp_ch6.adb index 975a96668df..d90ee41712e 100644 --- a/gcc/ada/exp_ch6.adb +++ b/gcc/ada/exp_ch6.adb @@ -7759,10 +7759,10 @@ package body Exp_Ch6 is return False; end if; - -- If the function is imported from a foreign language, we don't do - -- build-in-place, whereas Import (Ada) functions can do it. Note also - -- that it is OK for a build-in-place function to return a type with a - -- foreign convention because the machinery ensures there is no copying. + -- We never use build-in-place if the convention is other than Ada, + -- but note that it is OK for a build-in-place function to return a + -- type with a foreign convention because the machinery ensures there + -- is no copying. return (Kind in E_Function | E_Generic_Function or else diff --git a/gcc/ada/sem_util.adb b/gcc/ada/sem_util.adb index 3132446515b..a05ac74d35f 100644 --- a/gcc/ada/sem_util.adb +++ b/gcc/ada/sem_util.adb @@ -6163,9 +6163,12 @@ package body Sem_Util is elsif Is_Build_In_Place_Function (Func) then Set_Returns_By_Ref (Func); - -- In Ada 95, limited types are returned by reference + -- In Ada 95, limited types are returned by reference, but not if the + -- convention is other than Ada. - elsif Is_Limited_View (Typ) then + elsif Is_Limited_View (Typ) + and then not Has_Foreign_Convention (Func) + then Set_Returns_By_Ref (Func); end if; end Compute_Returns_By_Ref;