From patchwork Fri May 26 07:36:55 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: 70152 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BE0F5395A073 for ; Fri, 26 May 2023 07:50:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BE0F5395A073 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1685087437; bh=DdwpgOkRtqvaP1O+gyb/OO5osH5wJiQR99mktOUc+y4=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=SjxDJqsytHgBDXeNxoasA1483n7N1JPspgUCXewxQFS0t7aK/3GTQMk8FDsk+mEpN 7n1yqvYZRCxytg8BEHU1G3KzTbUmLk9KgPfIt+sNLl5R3k2sz7Ddw/XMJysNTxtYAG OeN1UWTI95n7gbRWmzZn6Q9Cynh7EOUhJ+bAmr30= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by sourceware.org (Postfix) with ESMTPS id 17DDA3834695 for ; Fri, 26 May 2023 07:36:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 17DDA3834695 Received: by mail-wm1-x32f.google.com with SMTP id 5b1f17b1804b1-3f50020e0f8so10219725e9.0 for ; Fri, 26 May 2023 00:36:58 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685086617; x=1687678617; 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=DdwpgOkRtqvaP1O+gyb/OO5osH5wJiQR99mktOUc+y4=; b=CWF+9T/N6SOoY7FdQ9N2aPBnWNjeolUdP7CopsclWoHiMQHo9OEcYRhuvfRE5vd2TS CbZE0s97lSc6yHeAEHNfhPUrsLxOo2AkudYun9Ynv47VSPgCadi80ZC86Nw6SAfknPAN ViZ0bppuvxeQzfcwiUbBwJYgxDd9OTF+1aj3NRJC8dEONsmVCIsBZNtvQvZ0SYfe0NDY Ut2lTOj+aH+GOSNdcXA4CFGrMtzSjMAI/TERopnUDOfiIjI0x6pEE3f1jMrJRQy0m0rq xZtX/5ecBjHldqiehE2/HeYuKJDBtPo5j2Cuwv/Xebnt9B3uGZVyt4OK1pCF3oZv54xa qrIQ== X-Gm-Message-State: AC+VfDz0+h/5KCc6iKU9Sfu+r2snFUOMlPzluG4cJVShTjSXD/z5AxSe 1GYTQcIWJZTIlk0vfFt5NoTJHZCVNTkMlMUpLQCW8Q== X-Google-Smtp-Source: ACHHUZ7ZD2gWF08SwgwURZnZWTZUZlXd5T6E2/j5PdTDWD98UtfZ+cIQMVhvSzDDbdr2q/o3blSG2A== X-Received: by 2002:a05:600c:1d90:b0:3f6:46e:b221 with SMTP id p16-20020a05600c1d9000b003f6046eb221mr4294578wms.7.1685086617034; Fri, 26 May 2023 00:36:57 -0700 (PDT) Received: from localhost.localdomain ([2001:861:3382:1a90:777b:eef4:6f79:f26f]) by smtp.gmail.com with ESMTPSA id u15-20020a05600c210f00b003f42d8dd7d1sm7976805wml.7.2023.05.26.00.36.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 May 2023 00:36:56 -0700 (PDT) To: gcc-patches@gcc.gnu.org Cc: Javier Miranda Subject: [COMMITTED] ada: Crash on function returning allocated object containing tasks Date: Fri, 26 May 2023 09:36:55 +0200 Message-Id: <20230526073655.2069914-1-poulhies@adacore.com> X-Mailer: git-send-email 2.40.0 MIME-Version: 1.0 X-Spam-Status: No, score=-13.6 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 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+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" From: Javier Miranda The frontend crashes when a function returns an object of a limited type that may have task components, has discriminants, and the object is created with an allocator. gcc/ada/ * exp_ch4.adb (Expand_N_Allocator): If an allocator with constraints is called in the return statement of a function returning a general access type, then propagate to the itype the master of the general access type (since it is the master associated with the returned object). Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/exp_ch4.adb | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/gcc/ada/exp_ch4.adb b/gcc/ada/exp_ch4.adb index f894da58888..5c9c6686c01 100644 --- a/gcc/ada/exp_ch4.adb +++ b/gcc/ada/exp_ch4.adb @@ -4991,6 +4991,25 @@ package body Exp_Ch4 is Expand_N_Full_Type_Declaration (Parent (Base_Type (PtrT))); + -- When the allocator has a subtype indication then a + -- constraint is present and an itype has been added by + -- Analyze_Allocator as the subtype of this allocator. + + -- If an allocator with constraints is called in the + -- return statement of a function returning a general + -- access type, then propagate to the itype the master + -- of the general access type (since it is the master + -- associated with the returned object). + + elsif Is_Itype (PtrT) + and then Ekind (Current_Scope) = E_Function + and then Ekind (Etype (Current_Scope)) + = E_General_Access_Type + and then In_Return_Value (N) + then + Set_Master_Id (PtrT, + Master_Id (Etype (Current_Scope))); + -- The only other possibility is an itype. For this -- case, the master must exist in the context. This is -- the case when the allocator initializes an access