From patchwork Mon May 22 08:49: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: 97177 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1299382vqo; Mon, 22 May 2023 01:50:58 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5QoCxV72+SGP4Gb0q7kKojDIOPRERwYUCk9bZZmMiybwfR+TDSCl0YEP6mO+VFlm5mVHJR X-Received: by 2002:a17:907:e8c:b0:96f:678:d2e2 with SMTP id ho12-20020a1709070e8c00b0096f0678d2e2mr10279870ejc.11.1684745458334; Mon, 22 May 2023 01:50:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684745458; cv=none; d=google.com; s=arc-20160816; b=UwC2hFXmdYzUD+p8L/W7QeS+YgIm1r4qrhB3iuxsarv4tvhpxp7XXh75+f8LohdZ1v KFrUP3yTNv6HVgflogAL5UvZntOtk3laTnozc/zn9B9mqe6SEmmlX0vMu2q47P27uIMh v4SpeI0LulvycbUp1jGMQzgDLTq7g8aTzaRDjdNUp0KWBF55fXj6QRdRJT9Fxwo8HiSq 9mNtoIotg7oNKyiRGOqNoWI4xZ1IV6EK0a2CMrV27Wd0eeKDJTUUKcSVB8DQWnBzkPs7 LGcrHM04T16kVGZs1to3mKySzTm/Yc86wKNEK5tun76OFZ0PI5+d/U9wlzOz5z6HyVka ylaQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:cc :to:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=iB5VyjUJlrCk0iFRkrjmyuTZwUArX0S9uaiEsSiVyd4=; b=hbIFwBrb1pGNlTqJ5QHp73Bi2thLa/w6CjW5uBKE4fKUcYO0GK9CWz1uigxIQwriLo 4h81jxAodzw8UCZ3THq2j0qdgW0F8/j0lbCbB1Cpe+p4qyJ2zqxLbNwHVYYDBurNnulE pDXrtATk5ZTR8JaHZJJ/vgNN6BF2ACdOvQoTPLmFdeMcezCeA44vdXNsd6uZrSa6icUt AubvPW3hzIKwS87wAO2scxOP37rz7TSKwAD1hrGIcNx7hKf7Y1UzdvWFvDT6dSSkptHk YL92T4JkJFJ24dXiNk0w1HR1myzzpF4Opxsa4GtYZJI5xBlfTsj3qoAwzmA+DU1tQjfR /+Ew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Y4W364fJ; 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=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id gq14-20020a170906e24e00b0094f23c63a86si2558871ejb.618.2023.05.22.01.50.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 May 2023 01:50:58 -0700 (PDT) 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=@gcc.gnu.org header.s=default header.b=Y4W364fJ; 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=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 044B93858C50 for ; Mon, 22 May 2023 08:50:02 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 044B93858C50 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1684745402; bh=iB5VyjUJlrCk0iFRkrjmyuTZwUArX0S9uaiEsSiVyd4=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=Y4W364fJE0vPHsdMhF/xc7Eit0vt0c2VMBhx4A+5WVEIW3+mVGa7iquIqzZj3p8c+ C9lNtnmXE02sb2XpJUzsC4ewyKMF0+J4GvB9A+ZqbNVAysQ4N1Wa7znKbwyR87QTmq PHyilJmy+IdTVTjdCEZo+7sUJloUkdM/vWScAeFk= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by sourceware.org (Postfix) with ESMTPS id 1336F385842E for ; Mon, 22 May 2023 08:49:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1336F385842E Received: by mail-wm1-x32d.google.com with SMTP id 5b1f17b1804b1-3f6042d605dso6096555e9.2 for ; Mon, 22 May 2023 01:49:12 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684745351; x=1687337351; 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=iB5VyjUJlrCk0iFRkrjmyuTZwUArX0S9uaiEsSiVyd4=; b=GWNW/OBTqE7rrf+7ArP1WuP34NqLrTN86Q/KdyuYS7P8pQ8HBkEOtvMzqljiLU+WDN zghkYmpEU4sOR5/ieR41jrLVwPqLlkOP8r3Qb2ypzqkcy2RKsXJRDzXF7ZAMWtwWctzC tOcOT3DR2uMU41KcSCd8RkYft++jm/miakPTFdupTYc2XRupQjDajMP8ZD8Pu+hy81ZN QBeRRGplcQ+uUL1iArXUW6sLR7MCz8cdM1N2MamUjdOXK6aX/TDwwAnMqVDL5CC2NtEX K6OkZMmOCx2ePTsa2JXUIqenj5arbbbfZ2kPHMij3x99YupcY6c6JSMeiCgv9s0fJkR/ anEA== X-Gm-Message-State: AC+VfDzof8NSkFJoXSVUkxHzzjE4e9Co6sxgN7yaFALcL9ZffPe69Ne2 duuVUvSEo7lYiGy0TpQMtV0z/VLTZ4gF25fpxsoIpQ== X-Received: by 2002:a7b:cb9a:0:b0:3f4:f51b:c04a with SMTP id m26-20020a7bcb9a000000b003f4f51bc04amr7217569wmi.37.1684745350777; Mon, 22 May 2023 01:49:10 -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 3-20020a05600c230300b003f6042d6da0sm2957936wmo.16.2023.05.22.01.49.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 May 2023 01:49:10 -0700 (PDT) To: gcc-patches@gcc.gnu.org Cc: Bob Duff Subject: [COMMITTED] ada: prevent infinite recursion in Collect_Types_In_Hierarchy Date: Mon, 22 May 2023 10:49:06 +0200 Message-Id: <20230522084906.1725082-1-poulhies@adacore.com> X-Mailer: git-send-email 2.40.0 MIME-Version: 1.0 X-Spam-Status: No, score=-13.5 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+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766583653664666481?= X-GMAIL-MSGID: =?utf-8?q?1766583653664666481?= From: Bob Duff In (illegal) mutually-dependent type declarations, it is possible for Etype (Etype (Typ)) to point back to Typ. This patch stops the recursion in such cases. gcc/ada/ * sem_util.adb (Process_Type): Stop the recursion. * exp_aggr.adb (Build_Record_Aggr_Code): Add assertion. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/exp_aggr.adb | 1 + gcc/ada/sem_util.adb | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/gcc/ada/exp_aggr.adb b/gcc/ada/exp_aggr.adb index fe61e0ec90b..58831bd51ca 100644 --- a/gcc/ada/exp_aggr.adb +++ b/gcc/ada/exp_aggr.adb @@ -3837,6 +3837,7 @@ package body Exp_Aggr is Comp := First (Component_Associations (N)); while Present (Comp) loop Selector := Entity (First (Choices (Comp))); + pragma Assert (Present (Selector)); -- C++ constructors diff --git a/gcc/ada/sem_util.adb b/gcc/ada/sem_util.adb index 1d8d4fc30f8..9cf21953fea 100644 --- a/gcc/ada/sem_util.adb +++ b/gcc/ada/sem_util.adb @@ -6235,6 +6235,19 @@ package body Sem_Util is -- Examine parent type if Etype (Typ) /= Typ then + -- Prevent infinite recursion, which can happen in illegal + -- programs. Silently return if illegal. For now, just deal + -- with the 2-type cycle case. Larger cycles will get + -- SIGSEGV at compile time from running out of stack. + + if Etype (Etype (Typ)) = Typ then + if Total_Errors_Detected = 0 then + raise Program_Error; + else + return; + end if; + end if; + Process_Type (Etype (Typ)); end if;