From patchwork Tue Dec 19 14:31:06 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: 181010 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:24d3:b0:fb:cd0c:d3e with SMTP id r19csp1981198dyi; Tue, 19 Dec 2023 06:36:35 -0800 (PST) X-Google-Smtp-Source: AGHT+IH1CmosUBp/VfUZwKhDYnaUrV7gT92jFyz05WDWAAAyoQmEAqRhckSXKSLJT5X/Gp7ytCws X-Received: by 2002:a05:6214:acd:b0:67f:291a:b2a4 with SMTP id g13-20020a0562140acd00b0067f291ab2a4mr6482429qvi.32.1702996595177; Tue, 19 Dec 2023 06:36:35 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1702996595; cv=pass; d=google.com; s=arc-20160816; b=gNOolppei+rhtRiu4Us9Rh3uqnrHfMgIRCDlJKa85C0Shr/1o1YzdA2hNoXKjpWrXO vkcrZHScGtBA4VDttsOxM7+g5L4Ie664VBTpmWrXB0dm2NmliwpzJ6WagNWVInj8WF60 yoiIY1ngRU+R2EJgz1MWarcBEZ5O8tQhoa2Ol1TUFOGkN52Q2bugCRjX57x5AsyXWMyG sbkh2466hYmUjKBtlVr/2aqcOleixJx6DsAhWRnwFj3OKfLouPm9XUuL3b0K22FNxZhE IV2U1lxHcU0YQQP/SreHT5amxerT3bk26EVaHKqqi/QgZQEtKJT4fVXxF1XrAk3zbu5O bMkg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=ZKK24RzLW1cWShcphjd8K1YkPFuBQ7OtJSniuxGccQI=; fh=V3FUX71dhq7uYqp2NU3QsSvdKCASDvtMIqKaZekiAR8=; b=oxyVZp5aGl/3atEx7OuG4jTzjSBPAoqpdqcMpE30AiChYYwOMJd+huDr6g/fhipMrl ZMxtUqUuusoNQieTkBuiLXCx/pipyaqPrcUPiQnTtJVxHiBHNHp58lZ3SRenhW7FYWD2 YFKoGMJxg/x/MSbwNbQRofBgFiX0n/wseSdz5Sz46X+95hxQqXtvTzlqIZzL2YT6TCYB 845iYjczLoosi0jG9Sj/eqfM3mR+m/ZvSsdTWsdEus4U2JSjnVAad5eQU95hLLVuie7N b/MHSJDUP+/z8g0j1Cc764/ON4J2SVxm+cSMU3Kzw7OYmmfFu59oJLvrJax5O3fFzsNu zotw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@adacore.com header.s=google header.b=Aih9gjrJ; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=adacore.com Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id pe26-20020a056214495a00b0067ec6939ef8si23316420qvb.148.2023.12.19.06.36.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Dec 2023 06:36:35 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@adacore.com header.s=google header.b=Aih9gjrJ; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=adacore.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id AEDF0380EF75 for ; Tue, 19 Dec 2023 14:33:23 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) by sourceware.org (Postfix) with ESMTPS id E8AAD3882659 for ; Tue, 19 Dec 2023 14:31:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E8AAD3882659 Authentication-Results: sourceware.org; dmarc=pass (p=none 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 E8AAD3882659 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::336 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702996270; cv=none; b=cF2s+1Vlt+S0PxTQAjz7UnS8MtbDD+3s4S742cnRTlBzlkTXInmIwzEgwY5rzxazFgs7sEedLhOBx94x4BsEqhC9P53CeFSVLq5QlTJx43N7yL/l1JNcS7QxxHyL/u2f4MDipH6+0a9YvZhAKicAUj5M7MKD6t5PHP6rbLRjO04= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702996270; c=relaxed/simple; bh=X0oDnRUVKvOkgdyR9+qc9KZDauqtozXxYp0yfC9nnJ4=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=WQVO4gHkOtgYePazktwlfuWV1759q95cRZJaZdRRDdfWYimDFbDMIhwr2MTCcYBepvWbhsEgZjM4SNTpvDsKHTztofyyXcWkB6LNIXUBkcuZwzmpAVsr0NAN9dwmEddjCwTRdnTZB8rfTO7cEmNxJifzk54tFizPVB7DUuxE8WU= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wm1-x336.google.com with SMTP id 5b1f17b1804b1-40c339d2b88so49747275e9.3 for ; Tue, 19 Dec 2023 06:31:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1702996268; x=1703601068; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=ZKK24RzLW1cWShcphjd8K1YkPFuBQ7OtJSniuxGccQI=; b=Aih9gjrJ+W0d/T/9SEGKB9J9GtsLSFD0bHcVyuaurAjzNjWaL7S1mywPlrOfV4FMsQ b4TsaCZJR4z1k96oHFhgtXeYhnTB+M/FvsYHKaq5paoeA9NOl2VSFdUbHUJLdPG2vhnP fTE5ZRqKsbFgLY4NNcYbOBRyEzZXf7b1mslg9t2JXWM0Hgb+eV0ny7mH4XAYSg4Y/dpm TjrrBqg9GqmEbU6AUeCQYJ4qhbKGgJiSOM2/1UYBYMqt1p4w/8Yslht/D8opgYiWeHm8 PMUC8i6cEXhbkE2ncKFxuYjl8bJM5BAr1ph7bNiH3dtz7r9RIThpTsWhpi+k5UZubi1W nVMQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702996268; x=1703601068; 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=ZKK24RzLW1cWShcphjd8K1YkPFuBQ7OtJSniuxGccQI=; b=eiLxpMpdW4z4bgT32mPbx1GlnZQyx4WJfGIevgYAID27QSigaNtpPy38G23YTr2J8K rMzS+3I8TW/ZXHKRZfOATLa6vPh2DLovi9wdNLpbZ2iIng5SPf7LgedguY8FIg84LAV4 lLo9TN3GrdNeE8mZmoNtdw4SBfB4e1li/8ICpTS82hxpV3ZyHQj18g8KdQCDtFqU1DYs x/HQTLGp5AKi1X6K4AgkK4oMY+gNcTLvGd69KbwBxpjcpdaoBDqgoTT6MIBcTLHzKEiM og0NZ4IKF2IoF/R5kt4iHviVELDX3nfnXsgZWlNo48JWZuhYMpp8U7+q6Ib84qE+qxmS q8jw== X-Gm-Message-State: AOJu0YyPS0wCf669ArUVA+9r82lQBk5bHh8Enpg7JIf3GiH6rgiOENNV wRjVf0kQKA4PUTgtJ0wllADkTwiM/2tt01PAldo= X-Received: by 2002:a05:600c:218e:b0:40c:23b9:616 with SMTP id e14-20020a05600c218e00b0040c23b90616mr9268886wme.169.1702996267799; Tue, 19 Dec 2023 06:31:07 -0800 (PST) Received: from poulhies-Precision-5550.lan ([2001:861:3382:1a90:fe1e:443:c34f:edaa]) by smtp.gmail.com with ESMTPSA id w20-20020a05600c475400b0040b4fca8620sm3066107wmo.37.2023.12.19.06.31.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Dec 2023 06:31:07 -0800 (PST) From: =?utf-8?q?Marc_Poulhi=C3=A8s?= To: gcc-patches@gcc.gnu.org Cc: Viljar Indus Subject: [COMMITTED] ada: Check all interfaces for valid iterator type Date: Tue, 19 Dec 2023 15:31:06 +0100 Message-ID: <20231219143106.456073-1-poulhies@adacore.com> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 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, KAM_ASCII_DIVIDERS, 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785721357404835291 X-GMAIL-MSGID: 1785721357404835291 From: Viljar Indus gcc/ada/ * sem_ch13.adb (Valid_Default_Iterator): Check all interfaces for valid iterator type. Also improve error reporting. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/sem_ch13.adb | 103 +++++++++++++++++++++++++++++++++++++------ 1 file changed, 90 insertions(+), 13 deletions(-) diff --git a/gcc/ada/sem_ch13.adb b/gcc/ada/sem_ch13.adb index 8f6fa3af0f8..6513afa0b1c 100644 --- a/gcc/ada/sem_ch13.adb +++ b/gcc/ada/sem_ch13.adb @@ -5876,39 +5876,116 @@ package body Sem_Ch13 is ------------------------------ procedure Check_Iterator_Functions is - function Valid_Default_Iterator (Subp : Entity_Id) return Boolean; - -- Check one possible interpretation for validity + function Valid_Default_Iterator (Subp : Entity_Id; + Ref_Node : Node_Id := Empty) + return Boolean; + -- Check one possible interpretation for validity. If + -- Ref_Node is present report errors on violations. ---------------------------- -- Valid_Default_Iterator -- ---------------------------- - function Valid_Default_Iterator (Subp : Entity_Id) return Boolean is - Root_T : constant Entity_Id := Root_Type (Etype (Etype (Subp))); - Formal : Entity_Id; + function Valid_Default_Iterator (Subp : Entity_Id; + Ref_Node : Node_Id := Empty) + return Boolean + is + Return_Type : constant Entity_Id := Etype (Etype (Subp)); + Return_Node : Node_Id; + Root_T : constant Entity_Id := Root_Type (Return_Type); + Formal : Entity_Id; + + function Valid_Iterator_Name (E : Entity_Id) return Boolean + is (Chars (E) in Name_Forward_Iterator | Name_Reversible_Iterator); + + function Valid_Iterator_Name (L : Elist_Id) return Boolean; + + ------------------------- + -- Valid_Iterator_Name -- + ------------------------- + + function Valid_Iterator_Name (L : Elist_Id) return Boolean + is + Iface_Elmt : Elmt_Id := First_Elmt (L); + begin + while Present (Iface_Elmt) loop + if Valid_Iterator_Name (Node (Iface_Elmt)) then + return True; + end if; + Next_Elmt (Iface_Elmt); + end loop; + + return False; + end Valid_Iterator_Name; begin + if Subp = Any_Id then + if Present (Ref_Node) then + + -- Subp is not resolved and an error will be posted about + -- it later + + Error_Msg_N ("improper function for default iterator!", + Ref_Node); + end if; + + return False; + end if; + if not Check_Primitive_Function (Subp) then + if Present (Ref_Node) then + Error_Msg_N ("improper function for default iterator!", + Ref_Node); + Error_Msg_Sloc := Sloc (Subp); + Error_Msg_NE + ("\\default iterator defined # " + & "must be a primitive function", + Ref_Node, Subp); + end if; + return False; + end if; -- The return type must be derived from a type in an instance -- of Iterator.Interfaces, and thus its root type must have a -- predefined name. - elsif Chars (Root_T) /= Name_Forward_Iterator - and then Chars (Root_T) /= Name_Reversible_Iterator + if not Valid_Iterator_Name (Root_T) + and then not (Has_Interfaces (Return_Type) and then + Valid_Iterator_Name (Interfaces (Return_Type))) then - return False; + if Present (Ref_Node) then - else - Formal := First_Formal (Subp); + Return_Node := Result_Definition (Parent (Subp)); + + Error_Msg_N ("improper function for default iterator!", + Ref_Node); + Error_Msg_Sloc := Sloc (Return_Node); + Error_Msg_NE ("\\return type & # " + & "must inherit from either " + & "Forward_Iterator or Reversible_Iterator", + Ref_Node, Return_Node); + end if; + + return False; end if; + Formal := First_Formal (Subp); + -- False if any subsequent formal has no default expression Next_Formal (Formal); while Present (Formal) loop if No (Expression (Parent (Formal))) then + if Present (Ref_Node) then + Error_Msg_N ("improper function for default iterator!", + Ref_Node); + Error_Msg_Sloc := Sloc (Formal); + Error_Msg_NE ("\\formal parameter & # " + & "must have a default expression", + Ref_Node, Formal); + end if; + return False; end if; @@ -5920,6 +5997,8 @@ package body Sem_Ch13 is return True; end Valid_Default_Iterator; + Ignore : Boolean; + -- Start of processing for Check_Iterator_Functions begin @@ -5940,9 +6019,7 @@ package body Sem_Ch13 is -- Flag the default_iterator as well as the denoted function. - if not Valid_Default_Iterator (Entity (Expr)) then - Error_Msg_N ("improper function for default iterator!", Expr); - end if; + Ignore := Valid_Default_Iterator (Entity (Expr), Expr); else declare