From patchwork Tue May 10 08:20:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierre-Marie de Rodat X-Patchwork-Id: 1628975 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=DO9TznYW; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KyBKH2Lsgz9sFx for ; Tue, 10 May 2022 18:38:59 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 71483383800D for ; Tue, 10 May 2022 08:38:56 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 71483383800D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1652171936; bh=nsJCYXb3e2YCVGICGNpJWekG3q6cbWej7KQIybdXYa8=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=DO9TznYWf0QBvm9c1Ttbgn58Lu4fJTASSXh2MRzZFQmipadHguoxjkFacaIayCnt+ J3kyxykoA04XOm18jTc4YuhJoqf1uGssMTlcQcE3fk20LVz7C9VN6n+OolJfDGQgwS TNSK8en+cuhL03WA4asHjDP3r+9sRbAauIIEqfAc= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by sourceware.org (Postfix) with ESMTPS id E2FB63888838 for ; Tue, 10 May 2022 08:20:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E2FB63888838 Received: by mail-wr1-x42a.google.com with SMTP id q23so22665651wra.1 for ; Tue, 10 May 2022 01:20:55 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition; bh=nsJCYXb3e2YCVGICGNpJWekG3q6cbWej7KQIybdXYa8=; b=BgLtX5+D8sqwCGcRRb6yWvQhyxkan7J8/GBFadQb14b3IQDnpB6SLLdrBqf6R9twi1 dhdbVFfHE0A+pCje8pVVc7GOVMK4vLLu1iVNwS51JDQIE+a6aoBzeMFf0WjPk3AT0O4n +CKheACtcAA2Wh82LGOvrYMEvqEgeIXgQ1hOhkR0jBLpDxLLhfbJqzbUTcTGennRoxdR 5fW+r5FBdoVIeMJoBGRhAllxTrCEJ6spKeXHa+VwTgPWFchKxANuIStGlxPijw+DMKK8 vfM+bMpB2ISWInYEEZY+mTb7vEdB7pXLvCdECybexAi82+5aNwKNoqGfzHG8nTSU1Cpa zehA== X-Gm-Message-State: AOAM531WmIebFpCgKkuj6OBfsTyMvT0z6KwExG47PkGbuZwvs5lRjuvg QD9T6+fvRLBQcP0EoACD0zkrS6RP4rBhzA== X-Google-Smtp-Source: ABdhPJzYvFQgI49WbjCV6F61ygbk88YrDsOd66GWGYZyksYJJB8CU40YGuptYytx2hIdMSK2TFxTcQ== X-Received: by 2002:adf:e6c3:0:b0:20a:e1a1:b176 with SMTP id y3-20020adfe6c3000000b0020ae1a1b176mr17059326wrm.291.1652170854663; Tue, 10 May 2022 01:20:54 -0700 (PDT) Received: from adacore.com ([45.147.211.82]) by smtp.gmail.com with ESMTPSA id e20-20020adf9bd4000000b0020c61af5e1fsm13825173wrc.51.2022.05.10.01.20.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 May 2022 01:20:54 -0700 (PDT) Date: Tue, 10 May 2022 08:20:53 +0000 To: gcc-patches@gcc.gnu.org Subject: [Ada] Failure compiling "for ... of" loop over a slice Message-ID: <20220510082053.GA3028958@adacore.com> MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-13.2 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.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: Pierre-Marie de Rodat via Gcc-patches From: Pierre-Marie de Rodat Reply-To: Pierre-Marie de Rodat Cc: Steve Baird Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" In some cases involving a "for ... of" loop (not to be confused with the more common "for ... in" loop) iterating over a slice, compilation would fail with an internal compiler error. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * sem_util.adb (Get_Actual_Subtype): If a new subtype is built, do not freeze it if Expander_Active is False. The idea here is to avoid generating an unwanted Freeze_Node for a subtype that has been conjured up solely for purposes of preanalysis. diff --git a/gcc/ada/sem_util.adb b/gcc/ada/sem_util.adb --- a/gcc/ada/sem_util.adb +++ b/gcc/ada/sem_util.adb @@ -10724,14 +10724,24 @@ package body Sem_Util is Set_Is_Itype (Atyp); Analyze (Decl, Suppress => All_Checks); Set_Associated_Node_For_Itype (Atyp, N); - Set_Has_Delayed_Freeze (Atyp, False); - - -- We need to freeze the actual subtype immediately. This is - -- needed, because otherwise this Itype will not get frozen - -- at all, and it is always safe to freeze on creation because - -- any associated types must be frozen at this point. - - Freeze_Itype (Atyp, N); + if Expander_Active then + Set_Has_Delayed_Freeze (Atyp, False); + + -- We need to freeze the actual subtype immediately. This is + -- needed because otherwise this Itype will not get frozen + -- at all; it is always safe to freeze on creation because + -- any associated types must be frozen at this point. + + -- On the other hand, if we are performing preanalysis on + -- a conjured-up copy of a name (see calls to + -- Preanalyze_Range in sem_ch5.adb) then we don't want + -- to freeze Atyp, now or ever. In this case, the tree + -- we eventually pass to the back end should contain no + -- references to Atyp (and a freeze node would contain + -- such a reference). That's why Expander_Active is tested. + + Freeze_Itype (Atyp, N); + end if; return Atyp; -- Otherwise we did not build a declaration, so return original