From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lf1-x12b.google.com (mail-lf1-x12b.google.com [IPv6:2a00:1450:4864:20::12b]) by sourceware.org (Postfix) with ESMTPS id 0A4EB3858D38 for ; Tue, 13 Jun 2023 07:38:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0A4EB3858D38 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-lf1-x12b.google.com with SMTP id 2adb3069b0e04-4f6370ddd27so6223224e87.0 for ; Tue, 13 Jun 2023 00:38:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1686641923; x=1689233923; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=n84FON7DWDSK5rz4dsgeN8cg2Svx5H7Y91YFi2TX7PU=; b=E9nlodkrSMBWNjcI21u2YLhKPpVk9sui6yW8g9t5c05HxFTQsI6zdgSlqyuVyDx6// TLuTi6OetBRjXhO9iMLdUiF98b0XPwvtuyVQgNKI5u0c621lds8bYpuojZL60OtCRxwW d2dwxCDd2lvA6OMG947uOvp0oIFQSwOBQD12M/bK68uS8/wxPfPJoYLkHVZw1HPFW/ZV 9d6UylaU5bkTNsLJuaH+6kHbdipIO0HjbzUrPf+eq0mX5ZCZPN2JKjYWUx+xz6Rk0mZM RMO6STsWOvBcoma8ZEgLCORelflHjR5D7KAup21+QZunVnHSbk4zIoWPzsmVDkJAYOfL 7rZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686641923; x=1689233923; 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=n84FON7DWDSK5rz4dsgeN8cg2Svx5H7Y91YFi2TX7PU=; b=F+R/31tOU1/zZF/xwWlAmo7J4JeHdJXTaKqPbOuehVAA9IsZ2FwOPj5FH2WJnewbLF GL/5xfTlbP14j2aNzTp6/w24+0DjErCap6ba0s1p0NidfIYCCrzD30Cunb00A2AjDSH2 4H5t1syphidg/Zl2DK5m3Sa7Rub8yLtTKH7MZYZY/ID1CUqkl4AzDU2aklCgl5mqEO3F vAMaM9YUlauaZ/Y/o9x1IMfFftuKxCmtK2gQ/MQ4lso6Uwtx/JRhMS8iGIHP1ne6CMc9 Aw+RG39F5OxsViYciZ/Rad9hZl8fAIcIxiZTabxtclvOTLW1T+++IVUHHaqSXPuVnI37 hGAg== X-Gm-Message-State: AC+VfDyPuXlSu/6gvOAjgqR+kHLR6V0QgqSUqPLOREQ6sYdVBYzKwcGi Zk6fmi2WAfkNN60k9SANBC+dmoDl+jeyGqML4ASMEg== X-Google-Smtp-Source: ACHHUZ7/D7STwz7aP523HY/C6KQAPdqEmCHyc51GitxPcPCr7pjl+//n0/X2o57g30lU+Tee/21yFQ== X-Received: by 2002:a19:5f54:0:b0:4f3:a812:5ae with SMTP id a20-20020a195f54000000b004f3a81205aemr5278465lfj.37.1686641923579; Tue, 13 Jun 2023 00:38:43 -0700 (PDT) Received: from localhost.localdomain ([2001:861:3382:1a90:bfa8:5d29:40e5:cc66]) by smtp.gmail.com with ESMTPSA id n6-20020a7bc5c6000000b003f7f87ba116sm13490671wmk.19.2023.06.13.00.38.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Jun 2023 00:38:42 -0700 (PDT) From: =?UTF-8?q?Marc=20Poulhi=C3=A8s?= To: gcc-patches@gcc.gnu.org Cc: Bob Duff Subject: [COMMITTED] ada: Add missing ss_mark/ss_release in quantified expressions Date: Tue, 13 Jun 2023 09:38:41 +0200 Message-Id: <20230613073841.240638-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.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 List-Id: From: Bob Duff If a quantified expression says "for all ... of F(...)" where F(...) is a function call that returns on the secondary stack, we need to clean up the secondary stack. This patch adds the required ss_mark/ss_release in that case. gcc/ada/ * exp_ch4.adb (Expand_N_Quantified_Expression): Detect the secondary-stack case, and find the innermost scope where we should mark/release, and Set_Uses_Sec_Stack on that. Skip intermediate blocks and loops that are part of expansion. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/exp_ch4.adb | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/gcc/ada/exp_ch4.adb b/gcc/ada/exp_ch4.adb index fdaeb50512f..7b6e997e3e7 100644 --- a/gcc/ada/exp_ch4.adb +++ b/gcc/ada/exp_ch4.adb @@ -11116,6 +11116,32 @@ package body Exp_Ch4 is Freeze_Before (P, Etype (Var)); end; + -- For an expression of the form "for all/some X of F(...) => ...", + -- where F(...) is a function call that returns on the secondary stack, + -- we need to mark an enclosing scope as Uses_Sec_Stack. We must do + -- this before expansion, which can obscure the tree. Note that we + -- might be inside another quantified expression. Skip blocks and + -- loops that were generated by expansion. + + if Present (Iterator_Specification (N)) + and then Nkind (Name (Iterator_Specification (N))) = N_Function_Call + and then Needs_Secondary_Stack + (Etype (Name (Iterator_Specification (N)))) + then + declare + Source_Scope : Entity_Id := Current_Scope; + begin + while Ekind (Source_Scope) in E_Block | E_Loop + and then not Comes_From_Source (Source_Scope) + loop + Source_Scope := Scope (Source_Scope); + end loop; + + Set_Uses_Sec_Stack (Source_Scope); + Check_Restriction (No_Secondary_Stack, N); + end; + end if; + -- Create the declaration of the flag which tracks the status of the -- quantified expression. Generate: -- 2.40.0