From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=8ykrPzRhb5RpgGalp4GUOjWXIdz6nQs6Cz2m2gKYY7Q=; b=fVIQHOmrAkTZHcC7Q2KU6hqrE/JG9iH3JERX1CcM6UV9g4pSxyP5NvTPlv9Q4g2u8B RKAbf1hIuMezuKW3HcYPXpBv6tuSTfDaYghQSHrLuLkIgk5U+i24h/xDW6t5mlz3kaC9 QUULS6tDU6wgJt1NnPCmPbQSDKiBEq5WeicZeOmXROlWQDN/xZscQNUrtZvieq4ZLn/N sztlNm1Bk/grzw9pNZC8YUsljc+MMKCQZO3BXbGGYWZ4UY74329qarfgQMo7F/QR4J7H FQdR4UwP5jHZ/vciE080l80HtR/EgONEFWRrje+fM2b//D9Rr+uP9ofxX2bcsjIQW+zO 9VCg== 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-Google-Smtp-Source: AMrXdXvpqZ7WTjzLegC3mZgeFuu6xM7Vzoc0W1p1Kg0yS/yyxKkDMaaQepBphbYTXSzfBaJx4JAthQ== 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) From: =?UTF-8?q?Marc=20Poulhi=C3=A8s?= 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 Content-Transfer-Encoding: 8bit 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 List-Id: 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; -- 2.34.1