From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by sourceware.org (Postfix) with ESMTPS id 2CFBB3858032 for ; Tue, 27 Jun 2023 12:08:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2CFBB3858032 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-x436.google.com with SMTP id ffacd0b85a97d-313e1c27476so2728519f8f.1 for ; Tue, 27 Jun 2023 05:08:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1687867695; x=1690459695; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=JFKFQOlcZnm72khywhjWQhXGGgxbPDWvjapldcedg/c=; b=Ia6Vvzuu7H/PzlsZy141vDtyxkigDTQdrWo6dqTdW7hgTazhNRkUukscMJWlvDD4Xn 0NDx/28+XLps63HZpAVkdBOsghozo1u6NLrAlabGYA7RYd9s/ts6/twrDeHDnGb5cndT HjR42pFG/Om/qS/scrLF7ud8q2lD4k3AFZXzDlHO7HeP+Y4wdK497jmNfYPSEfjZWct8 MyHN42OQLXpQ8WTh6vrT0McGj82e6sGC0UhBAQoJ6657GMDf5Z8riUQIabbQWxIXXDxw zEcISPKngO4V3JPsFA3q1u8AEyj7Ot5TBNav6FguFQ/ARnQGvAjzEaF5KQy8omfRUCX1 fAeg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687867695; x=1690459695; 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=JFKFQOlcZnm72khywhjWQhXGGgxbPDWvjapldcedg/c=; b=bxgM32i7Eqs6on9CkymL+hVUdpiBSdSe5FGpEB4XIjP1BA/ckR3BVay3/QcnKmc1MQ ai/C63iPIr9sAtE51I8u2Bu9Tsoh18DOZqpId95v94lzJ2z+U1sZi/sto+lENxKKVBeJ nGrcqgNpPPY7SHGz1QLA31RlF3X7hJDBQXF45WPRe14KKS1PXuM9mANfLniLWXoaFb+f aKqfTzFycTkFzivN6muRNZZgq1zw4QN6HnzZ1iZ4uyoUtcHW0hZsL/KPMbT/7r3g3mYE J8fMjbeRWT6Aa32jK3wRN9AUIO0ORlp6mSZTyTcXSNp0LuOMiRFa6nbvZomweIxKsfDw l2NQ== X-Gm-Message-State: AC+VfDwmq0bZ7FI1Pefgyzr1MchVqlm1vB5RGUaSC9zDrw43N41xn3oA gvvNXCY++t+amnC56yrK1a3/d1p6Cs4y1Dx+c7h9RA== X-Google-Smtp-Source: ACHHUZ6ROhB3wpVroEJ295N5yJibjgUvYNzCaYR51OBlw7s5ef2VZ03+y6L1fi1l6lURnOydWiJbRw== X-Received: by 2002:a5d:56c3:0:b0:314:23e:c8fc with SMTP id m3-20020a5d56c3000000b00314023ec8fcmr1179824wrw.33.1687867694853; Tue, 27 Jun 2023 05:08:14 -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 l6-20020adff486000000b00313fd294d6csm2079481wro.7.2023.06.27.05.08.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Jun 2023 05:08:14 -0700 (PDT) From: =?UTF-8?q?Marc=20Poulhi=C3=A8s?= To: gcc-patches@gcc.gnu.org Cc: Eric Botcazou Subject: [COMMITTED] ada: Fix bad interaction between inlining and thunk generation Date: Tue, 27 Jun 2023 14:08:13 +0200 Message-Id: <20230627120813.3420523-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.7 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,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 This may cause the type of the RESULT_DECL of a function which returns by invisible reference to be turned into a reference type twice. gcc/ada/ * gcc-interface/trans.cc (Subprogram_Body_to_gnu): Add guard to the code turning the type of the RESULT_DECL into a reference type. (maybe_make_gnu_thunk): Use a more precise guard in the same case. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/gcc-interface/trans.cc | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/gcc/ada/gcc-interface/trans.cc b/gcc/ada/gcc-interface/trans.cc index b74bb0683bf..f5eadbbc895 100644 --- a/gcc/ada/gcc-interface/trans.cc +++ b/gcc/ada/gcc-interface/trans.cc @@ -3902,8 +3902,11 @@ Subprogram_Body_to_gnu (Node_Id gnat_node) gnu_return_var_elmt = NULL_TREE; /* If the function returns by invisible reference, make it explicit in the - function body. See gnat_to_gnu_subprog_type for more details. */ - if (TREE_ADDRESSABLE (gnu_subprog_type)) + function body, but beware that maybe_make_gnu_thunk may already have done + it if the function is inlined across units. See gnat_to_gnu_subprog_type + for more details. */ + if (TREE_ADDRESSABLE (gnu_subprog_type) + && TREE_CODE (TREE_TYPE (gnu_result_decl)) != REFERENCE_TYPE) { TREE_TYPE (gnu_result_decl) = build_reference_type (TREE_TYPE (gnu_result_decl)); @@ -11015,7 +11018,7 @@ maybe_make_gnu_thunk (Entity_Id gnat_thunk, tree gnu_thunk) same transformation as Subprogram_Body_to_gnu here. */ if (TREE_ADDRESSABLE (TREE_TYPE (gnu_target)) && DECL_EXTERNAL (gnu_target) - && !POINTER_TYPE_P (TREE_TYPE (DECL_RESULT (gnu_target)))) + && TREE_CODE (TREE_TYPE (DECL_RESULT (gnu_target))) != REFERENCE_TYPE) { TREE_TYPE (DECL_RESULT (gnu_target)) = build_reference_type (TREE_TYPE (DECL_RESULT (gnu_target))); -- 2.40.0