From patchwork Thu Sep 11 09:18:55 2025 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: 120046 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 4EB793858C41 for ; Thu, 11 Sep 2025 09:36:14 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4EB793858C41 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, secure) header.d=adacore.com header.i=@adacore.com header.a=rsa-sha256 header.s=google header.b=am8QAL+G X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org 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 4837D385840B for ; Thu, 11 Sep 2025 09:19:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4837D385840B Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 4837D385840B Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::42d ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1757582375; cv=none; b=fnC0MlggEjtpT0iN8k8STO/Ws0yJLjyBfhHdVVuDjk/Qf1CSbdnaNni3L3jiSwOied+cKAG8Ri5VTyaW6msSeZVhrN1ZRKaF2miMU+H34I5YPt1RKBB2QhzTWBt1HsRRkE2EaI+jK5qq0QpT6QlLgBOGGewIEfwvdwAEl96pBlc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1757582375; c=relaxed/simple; bh=mzBwZy8griOK1rC0TjwGG8kS08cD7vQ6Fnb5UCozWgA=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=UBwrJ78d47QmeNOVEDDL3lRQpvY8p4j7mI2ldJDZXYkjmA4JJ/1M/PJTpz4ei8a92zfgrAnRqOysneUuRgQ3QQry7IHrsI7W4KkBeZb062i52OLlKAObuQuzVLd8noz7JkohtI4njXqwyWv3xclk0iV5fTTIRZ7OI1eb5W/TDBg= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4837D385840B Received: by mail-wr1-x42d.google.com with SMTP id ffacd0b85a97d-3b9edf4cf6cso427376f8f.3 for ; Thu, 11 Sep 2025 02:19:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1757582374; x=1758187174; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=cwZV3jS76NBIPI0yxIkhlGiTVbLP4OLARJSSn/qS65U=; b=am8QAL+GKHFTNpmRGoGPIjOYpP9vro21mv/i/YoXAPHynRVL9IrLDmjk2j7Tn00u1s M/ELlCXzPvR1bsuW7K5qcVILhjDKjX7iqxVJiVK5dXTa+Ifkc5w6S1R9sn3ffcAWKzTQ Q1jBj35n0/7UJDb6eNWd/A5ggG2mPf/gJ6ThI/Lb5Cb+uh7kvqlxvY9nNwTL8xxQUhn9 aJzgrvpDkHRwefPI69MIpQBUqVfs6hdfFaCCE7QPnq2ZDNZsnaEMMQUdf6gnC8HjVZDn hZ+TXvbNh58ERs6FRUHGWIHpkUIlnxgLnHfBkmKshRfMlHQUZLd8WOORjetoWJgB7Nqx ijUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1757582374; x=1758187174; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to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+IEPXbvdhhPmPa22O5ekG1xdp46BZNuqbgBnxEb0si/g7C886geSTJkaxR/MGZOViry85+dr+A== X-Received: by 2002:adf:e64a:0:b0:3e7:61f8:f5e6 with SMTP id ffacd0b85a97d-3e761f8f871mr751736f8f.38.1757582373771; Thu, 11 Sep 2025 02:19:33 -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 ffacd0b85a97d-3e7607cd27dsm1649971f8f.41.2025.09.11.02.19.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Sep 2025 02:19:33 -0700 (PDT) From: =?utf-8?q?Marc_Poulhi=C3=A8s?= To: gcc-patches@gcc.gnu.org Cc: Viljar Indus Subject: [COMMITTED 23/31] ada: Check instantces of ghost iterator functions Date: Thu, 11 Sep 2025 11:18:55 +0200 Message-ID: <20250911091904.1505690-23-poulhies@adacore.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250911091904.1505690-1-poulhies@adacore.com> References: <20250911091904.1505690-1-poulhies@adacore.com> MIME-Version: 1.0 X-Spam-Status: No, score=-13.8 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 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~patchwork=sourceware.org@gcc.gnu.org From: Viljar Indus Since we do not analyze the policy errors for expanded code we need to check the functions specified in the Iterable aspect whenever we are analyzing an iterator spcification with that aspect. gcc/ada/ChangeLog: * sem_ch5.adb (Analyze_Iterator_Specification): Check ghost context of Iterable functions when handling iterator specifications with an Iterable aspect. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/sem_ch5.adb | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/gcc/ada/sem_ch5.adb b/gcc/ada/sem_ch5.adb index 1db5b75acbe3..a767ee0b560f 100644 --- a/gcc/ada/sem_ch5.adb +++ b/gcc/ada/sem_ch5.adb @@ -2160,7 +2160,10 @@ package body Sem_Ch5 is Loc : constant Source_Ptr := Sloc (N); Subt : constant Node_Id := Subtype_Indication (N); + Assoc : Node_Id; Bas : Entity_Id := Empty; -- initialize to prevent warning + Iter_Asp : Node_Id; + Iter_Func : Node_Id; Typ : Entity_Id; procedure Check_Reverse_Iteration (Typ : Entity_Id); @@ -2870,12 +2873,9 @@ package body Sem_Ch5 is -- in the container package. We obtain it by name for a predefined -- container, or through the Iterable aspect for a formal one. - if Has_Aspect (Typ, Aspect_Iterable) then - Set_Etype (Def_Id, - Get_Cursor_Type - (Parent (Find_Value_Of_Aspect (Typ, Aspect_Iterable)), - Typ)); - + Iter_Asp := Find_Aspect (Typ, Aspect_Iterable); + if Present (Iter_Asp) then + Set_Etype (Def_Id, Get_Cursor_Type (Iter_Asp, Typ)); else Set_Etype (Def_Id, Get_Cursor_Type (Typ)); Check_Reverse_Iteration (Etype (Iter_Name)); @@ -2884,6 +2884,25 @@ package body Sem_Ch5 is end if; end if; + -- Validate the ghost context of he iterator function used for the + -- iterable aspect. + + Iter_Asp := Find_Aspect (Typ, Aspect_Iterable); + if Present (Iter_Asp) then + Assoc := First (Component_Associations (Expression (Iter_Asp))); + while Present (Assoc) loop + Iter_Func := Expression (Assoc); + if Nkind (Iter_Func) in N_Has_Entity + and then Present (Entity (Iter_Func)) + and then Is_Ghost_Entity (Entity (Iter_Func)) + then + Check_Ghost_Context (Entity (Iter_Func), Parent (N)); + end if; + + Next (Assoc); + end loop; + end if; + -- Preanalyze the filter. Expansion will take place when enclosing -- loop is expanded.