From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by sourceware.org (Postfix) with ESMTPS id F13233856969 for ; Thu, 15 Jun 2023 08:04:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org F13233856969 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-x42d.google.com with SMTP id ffacd0b85a97d-307d58b3efbso5507931f8f.0 for ; Thu, 15 Jun 2023 01:04:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1686816264; x=1689408264; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=nj197O+QhjHMtYgbgiMMJCCeI17LyiB+t9WiRe0t8WQ=; b=En6uqa97eidTd4wA9udV7N2TFSu3IQ99MZgsdWYUMddfzcBv8YKCAPI7gjwN/14jjC OplhP/Tqlh67VoZREqt7+v7TO1XuO6CyPg8ccn0tjv42BTwhu068pIJZchfTQ4jwS9ze 9rgCHlTf2x19rBPgsVK9RfpZwofWmBkwTZrvRr7+/QVWtjBfSpX5J+AlcW7bUsbte19a uHJfu2nilegs4dzNshSVdQ0jtvUNXvWf1FVF1ZTfvnLyf1y9yNYCHvWeVOVWm/bhseJ1 SYpGFNzbNx7tx+ex/UpI5Zv3kmnxJeePN7pZKfHgLuCjawPKxUIpS113T0D45sDIGZJP 2Teg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686816264; x=1689408264; 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=nj197O+QhjHMtYgbgiMMJCCeI17LyiB+t9WiRe0t8WQ=; b=doFOE+prI7vrrZXsG+h2UhoN9PsrPMRgFSayvmw4PSagct2uElT6HwUezkJim3IKLT TgpSZLqPDriHTeevM2r/j9vR1KQIixIJPx6N83cgk3qb2liEyT0I59CePblbJQPhx8Gq Ks08QtI/cRI+eY8PCTTmIk/LZ8EBImCtXgnNkHoKvzHJ7vlGnrKAUNX9yCGr6VSoihfo jwCMxm6gCwOTYjS2uA22l+i31TN60EGrnY5RlOWdljFzD4vv5YXzaAOOwPJwUCSejAdz Ave4ziR3MdauguMA8tA6qotZb2WrjcJquU2l5QyZj/V7IvsHq59ciJIgXWbMQoThqEn/ fKFg== X-Gm-Message-State: AC+VfDwLJUcwHEuutX/rfkbZFL1gKu9dtX9px/LKKFe90/lNiSutOHen 9leH8w5qmYmgEQiYFBxHmPDOHX9aT+eFp2NLtP/IgA== X-Google-Smtp-Source: ACHHUZ7S+Cy2v7ttoOA+QwvUFEqROjiKThZXkYlf2zVPKDXuIkg5hLtXPy24oq+pg+J7Fv1xcavqsA== X-Received: by 2002:adf:ef0b:0:b0:30a:bf2b:e03c with SMTP id e11-20020adfef0b000000b0030abf2be03cmr10246210wro.23.1686816263274; Thu, 15 Jun 2023 01:04:23 -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 q3-20020adff503000000b0030fa3567541sm17160094wro.48.2023.06.15.01.04.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Jun 2023 01:04:22 -0700 (PDT) From: =?UTF-8?q?Marc=20Poulhi=C3=A8s?= To: gcc-patches@gcc.gnu.org Cc: Eric Botcazou Subject: [COMMITTED] ada: Fix too small secondary stack allocation for returned aggregate Date: Thu, 15 Jun 2023 10:04:21 +0200 Message-Id: <20230615080421.939923-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 restores the specific treatment of aggregates that are returned through an extended return statement in a function returning a class-wide type, and which was incorrectly dropped in an earlier change. gcc/ada/ * exp_ch3.adb (Make_Allocator_For_Return): Deal again specifically with an aggregate returned through an object of a class-wide type. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/exp_ch3.adb | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/gcc/ada/exp_ch3.adb b/gcc/ada/exp_ch3.adb index fbedc16ddd0..778eed7f16e 100644 --- a/gcc/ada/exp_ch3.adb +++ b/gcc/ada/exp_ch3.adb @@ -7167,9 +7167,20 @@ package body Exp_Ch3 is Expression => Alloc_Expr)); else - Alloc := - Make_Allocator (Loc, - Expression => New_Occurrence_Of (Typ, Loc)); + -- If the return object is of a class-wide type, we cannot use + -- its type for the allocator. Instead we use the type of the + -- expression, which must be an aggregate of a definite type. + + if Is_Class_Wide_Type (Typ) then + Alloc := + Make_Allocator (Loc, + Expression => New_Occurrence_Of (Etype (Expr), Loc)); + + else + Alloc := + Make_Allocator (Loc, + Expression => New_Occurrence_Of (Typ, Loc)); + end if; -- If the return object requires default initialization, then it -- will happen later following the elaboration of the renaming. -- 2.40.0