From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7871) id 5A2C83858028; Thu, 15 Jun 2023 08:03:00 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5A2C83858028 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1686816180; bh=jh2k0UXe0eKUZWK5vEG/lcImBnWZoBRJIGW9W+zEXzU=; h=From:To:Subject:Date:From; b=ug8Cd23p9MHnssEouM1ZV4eU8u3dKI8dixySGB/KuOWX9Vc5m7DDWIC77y2GgFRwk zKNrpIyDaBOis1ejQT63jL4+lKCZFquZr9ERd8idU0yGHHB3o2px2yr+yA0TBZLwVf FiDkEAZpR9KvBgOOVoF9BUCAg5w2QJGntHEHlQsk= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Marc Poulhi?s To: gcc-cvs@gcc.gnu.org Subject: [gcc r14-1857] ada: Fix too small secondary stack allocation for returned aggregate X-Act-Checkin: gcc X-Git-Author: Eric Botcazou X-Git-Refname: refs/heads/master X-Git-Oldrev: 3f3f37c3f72f4840ef2d304e00f5bc8c28374bce X-Git-Newrev: c8c5bf93aaa481d4b08491d4545b74e2b329d16d Message-Id: <20230615080300.5A2C83858028@sourceware.org> Date: Thu, 15 Jun 2023 08:03:00 +0000 (GMT) List-Id: https://gcc.gnu.org/g:c8c5bf93aaa481d4b08491d4545b74e2b329d16d commit r14-1857-gc8c5bf93aaa481d4b08491d4545b74e2b329d16d Author: Eric Botcazou Date: Sat May 13 10:55:44 2023 +0200 ada: Fix too small secondary stack allocation for returned aggregate 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. Diff: --- 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.