[{"id":3673799,"web_url":"http://patchwork.ozlabs.org/comment/3673799/","msgid":"<1986162f-dd7a-4724-a5cb-4443de377626@redhat.com>","list_archive_url":null,"date":"2026-04-06T16:38:45","subject":"Re: [PATCH] c++/modules: Fix entry-point detection for recursive\n clusters [PR118630]","submitter":{"id":4337,"url":"http://patchwork.ozlabs.org/api/people/4337/","name":"Jason Merrill","email":"jason@redhat.com"},"content":"On 4/5/26 12:11 PM, Nathaniel Shead wrote:\n> Bootstrapped and regtested on x86_64-pc-linux-gnu, OK for trunk/15?\n\nOK.\n\n> -- >8 --\n> \n> In r15-4861-g4a99443c5dd9a235022652ba0fb143c6370ea99d we added support\n> to handle recursive dependency clusters, where we need to find the\n> \"entry\" dependency that all other entities will hook off to ensure that\n> we stream merge keys in the correct order on read-in.\n> \n> The logic I'd used to track the entry bit was not completely correct\n> however, leading to assertion failures in 'sort_cluster' where we found\n> that entities were not marked maybe_recursive when they should have\n> been, or multiple entities were marked as the entry point.\n> \n> Consider a cycle of three entities in a cluster, 'A', 'B', and 'C',\n> where 'A' is the entry point.  By definition we walk into 'A' first, and\n> find one of the other entities, 'B'.  The old logic marked 'A' as the\n> entry and 'B' as maybe-recursive; so far this is correct.\n> \n> But then if we walk into 'B' and find 'C' is maybe-recursive, the old\n> logic would mark 'B' as the entry point (again!).  And likewise when we\n> walk into 'C' and find 'A'.  So we would end up with three entry points.\n> Similar issues could happen with other arrangements of dependencies.\n> \n> Instead, by aggressively marking everything we see as maybe-recursive,\n> and only marking an entry point if nothing we see is maybe-recursive, we\n> avoid this issue.  We should only be able to discover these other\n> entities through the entry point (A) and so this 'flood fill' behaviour\n> should ensure that all entities are correctly marked maybe-recursive,\n> and only A is marked as an entry-point.\n> \n> \tPR c++/118630\n> \n> gcc/cp/ChangeLog:\n> \n> \t* module.cc (depset::hash::add_dependency): Correct entry point\n> \tcorection for recursive clusters.\n> \n> gcc/testsuite/ChangeLog:\n> \n> \t* g++.dg/modules/late-ret-5.h: New test.\n> \t* g++.dg/modules/late-ret-5_a.H: New test.\n> \t* g++.dg/modules/late-ret-5_b.C: New test.\n> \n> Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>\n> ---\n>   gcc/cp/module.cc                            |  5 +++--\n>   gcc/testsuite/g++.dg/modules/late-ret-5.h   | 16 ++++++++++++++++\n>   gcc/testsuite/g++.dg/modules/late-ret-5_a.H |  6 ++++++\n>   gcc/testsuite/g++.dg/modules/late-ret-5_b.C |  6 ++++++\n>   4 files changed, 31 insertions(+), 2 deletions(-)\n>   create mode 100644 gcc/testsuite/g++.dg/modules/late-ret-5.h\n>   create mode 100644 gcc/testsuite/g++.dg/modules/late-ret-5_a.H\n>   create mode 100644 gcc/testsuite/g++.dg/modules/late-ret-5_b.C\n> \n> diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc\n> index 6958388e454..5828748a3e6 100644\n> --- a/gcc/cp/module.cc\n> +++ b/gcc/cp/module.cc\n> @@ -14855,9 +14855,10 @@ depset::hash::add_dependency (depset *dep)\n>        details.  */\n>     if (writing_merge_key)\n>       {\n> -      dep->set_flag_bit<DB_MAYBE_RECURSIVE_BIT> ();\n> -      if (!current->is_maybe_recursive ())\n> +      if (!dep->is_maybe_recursive () && !current->is_maybe_recursive ())\n>   \tcurrent->set_flag_bit<DB_ENTRY_BIT> ();\n> +      dep->set_flag_bit<DB_MAYBE_RECURSIVE_BIT> ();\n> +      current->set_flag_bit<DB_MAYBE_RECURSIVE_BIT> ();\n>       }\n>   \n>     if (dep->is_unreached ())\n> diff --git a/gcc/testsuite/g++.dg/modules/late-ret-5.h b/gcc/testsuite/g++.dg/modules/late-ret-5.h\n> new file mode 100644\n> index 00000000000..6f14d18e757\n> --- /dev/null\n> +++ b/gcc/testsuite/g++.dg/modules/late-ret-5.h\n> @@ -0,0 +1,16 @@\n> +// PR c++/118630\n> +\n> +namespace test1 {\n> +  template <typename> decltype([]{}) a();\n> +}\n> +\n> +namespace test2 {\n> +  template <typename T> struct invoke_result {};\n> +  template <typename T> struct foo {};\n> +\n> +  template <typename T>\n> +  auto b(T&& arg) -> foo<invoke_result<decltype(arg)>> {\n> +    invoke_result<decltype(arg)> a;\n> +    return {};\n> +  }\n> +}\n> diff --git a/gcc/testsuite/g++.dg/modules/late-ret-5_a.H b/gcc/testsuite/g++.dg/modules/late-ret-5_a.H\n> new file mode 100644\n> index 00000000000..b39b1d4529f\n> --- /dev/null\n> +++ b/gcc/testsuite/g++.dg/modules/late-ret-5_a.H\n> @@ -0,0 +1,6 @@\n> +// PR c++/118630\n> +// { dg-do compile { target c++20 } }\n> +// { dg-additional-options \"-fmodule-header\" }\n> +// { dg-module-cmi {} }\n> +\n> +#include \"late-ret-5.h\"\n> diff --git a/gcc/testsuite/g++.dg/modules/late-ret-5_b.C b/gcc/testsuite/g++.dg/modules/late-ret-5_b.C\n> new file mode 100644\n> index 00000000000..d22d7638127\n> --- /dev/null\n> +++ b/gcc/testsuite/g++.dg/modules/late-ret-5_b.C\n> @@ -0,0 +1,6 @@\n> +// PR c++/118630\n> +// { dg-do compile { target c++20 } }\n> +// { dg-additional-options \"-fmodules -fno-module-lazy\" }\n> +\n> +#include \"late-ret-5.h\"\n> +import \"late-ret-5_a.H\";","headers":{"Return-Path":"<gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org>","X-Original-To":["incoming@patchwork.ozlabs.org","gcc-patches@gcc.gnu.org"],"Delivered-To":["patchwork-incoming@legolas.ozlabs.org","gcc-patches@gcc.gnu.org"],"Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (1024-bit key;\n unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256\n header.s=mimecast20190719 header.b=CZnD1ZkI;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org\n (client-ip=2620:52:6:3111::32; helo=vm01.sourceware.org;\n envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org;\n receiver=patchwork.ozlabs.org)","sourceware.org;\n\tdkim=pass (1024-bit key,\n unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256\n header.s=mimecast20190719 header.b=CZnD1ZkI","sourceware.org; dmarc=pass (p=quarantine dis=none)\n header.from=redhat.com","sourceware.org; spf=pass smtp.mailfrom=redhat.com","server2.sourceware.org;\n arc=none smtp.remote-ip=170.10.129.124"],"Received":["from vm01.sourceware.org (vm01.sourceware.org\n [IPv6:2620:52:6:3111::32])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4fqFRh4Jpcz1y2d\n\tfor <incoming@patchwork.ozlabs.org>; Tue, 07 Apr 2026 02:40:00 +1000 (AEST)","from vm01.sourceware.org (localhost [127.0.0.1])\n\tby sourceware.org (Postfix) with ESMTP id 971AB4BA2E27\n\tfor <incoming@patchwork.ozlabs.org>; Mon,  6 Apr 2026 16:39:58 +0000 (GMT)","from us-smtp-delivery-124.mimecast.com\n (us-smtp-delivery-124.mimecast.com [170.10.129.124])\n by sourceware.org (Postfix) with ESMTP id 705384BA23DC\n for <gcc-patches@gcc.gnu.org>; Mon,  6 Apr 2026 16:38:51 +0000 (GMT)","from mail-qk1-f200.google.com (mail-qk1-f200.google.com\n [209.85.222.200]) by relay.mimecast.com with ESMTP with STARTTLS\n (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id\n us-mta-483-vge3m0ZoOL27-sBoHJrRhA-1; Mon, 06 Apr 2026 12:38:49 -0400","by mail-qk1-f200.google.com with SMTP id\n af79cd13be357-8cb6291d95aso1530509285a.1\n for <gcc-patches@gcc.gnu.org>; Mon, 06 Apr 2026 09:38:49 -0700 (PDT)","from [192.168.50.130]\n (130-44-146-247.s12789.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com.\n [130.44.146.247]) by smtp.gmail.com with ESMTPSA id\n af79cd13be357-8d40495cd93sm895320485a.23.2026.04.06.09.38.46\n (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128);\n Mon, 06 Apr 2026 09:38:46 -0700 (PDT)"],"DKIM-Filter":["OpenDKIM Filter v2.11.0 sourceware.org 971AB4BA2E27","OpenDKIM Filter v2.11.0 sourceware.org 705384BA23DC"],"DMARC-Filter":"OpenDMARC Filter v1.4.2 sourceware.org 705384BA23DC","ARC-Filter":"OpenARC Filter v1.0.0 sourceware.org 705384BA23DC","ARC-Seal":"i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1775493531; cv=none;\n b=T8dy+qsPLUmwWOuTFmVLwEu8GjB15F0rZ4fC89LTWRd1TtKpLrjMUdbGt+ob37XWgWjPhWMsbEPTunPhnHgXrMtuxC94nBTqbo9MZ2kdEBVXjbrO7cnx9HqmhF1mmqDIVX9LRb6ukWoa4IeYzE1ZCPQjzMj1QPdqTGcyNRX3EuI=","ARC-Message-Signature":"i=1; a=rsa-sha256; d=sourceware.org; s=key;\n t=1775493531; c=relaxed/simple;\n bh=7AF1NkdWJ8uvUj6DA2jZFP1m2hrNyIWroD1F/b1vjZc=;\n h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From;\n b=uOA99BJaKLf1Llaq6zfFCxJucMPEFvtt+Pku77Y2L1ezTKfnSO24pp8nwtZOp5EFA288IEdTi9C3d9q9c+BpibL6gtZSBozpggmgRGwB9zxnEMLQcQuSWuB4DFstfC8d2edr+AHP90mzI47yHZMpZLFZmllJUv0BhYcnNYNS7TM=","ARC-Authentication-Results":"i=1; server2.sourceware.org","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n s=mimecast20190719; t=1775493531;\n h=from:from:reply-to:subject:subject:date:date:message-id:message-id:\n to:to:cc:mime-version:mime-version:content-type:content-type:\n content-transfer-encoding:content-transfer-encoding:\n in-reply-to:in-reply-to:references:references;\n bh=afG/t/IQQEj+YXknRq6rDYO6s4ICKMG0P2BPcaNCLK0=;\n b=CZnD1ZkIZJgQE/nbIelAk497KEzbLORG0Nv2DixQ/a7X1QZDv7BtnF4ypA9Mjz/LY0Sm5/\n F/xGP7WgvaZ/n1uisM55PEEFBGX+0PoGor4PEFFJAx/cJ5AFjo6+0NJbQLPeGggS4f3crF\n DgUe1s0qHVZTmlvfg4ma9r0APA6vI0A=","X-MC-Unique":"vge3m0ZoOL27-sBoHJrRhA-1","X-Mimecast-MFC-AGG-ID":"vge3m0ZoOL27-sBoHJrRhA_1775493529","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=1e100.net; s=20251104; t=1775493528; x=1776098328;\n h=content-transfer-encoding:in-reply-to:from:content-language\n :references:to:subject:user-agent:mime-version:date:message-id\n :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id\n :reply-to;\n bh=afG/t/IQQEj+YXknRq6rDYO6s4ICKMG0P2BPcaNCLK0=;\n b=EaJeH4+BGqJdY7QhfyGzBLuhSB9ETsQLrcxWqoN7aA10mgmoyJS+4YIe77PS8kDOcl\n Bi9ItWxIESBGut9EYKU20Dbh5GWpchR6e3+PoNIEs9WrvMuaNk2DfYn+6wmo7n7aXbij\n NCEWYnva3Mz2ZwKFgw4dHPVFrEHNWHtbBRG4iNDiPcK3GrNQjqb7KPs51HUnxCrwCWvG\n 78DhXVCmdDo5imPO92gl34O3NKPmW8k1HUWp2d2B5HgT4jrQuXEHJ5TCEn1Wd+S3ZEtx\n bqnHLSQ1d5LFPQJgtJrZ2iPRTUJv3v7Yv7ppM4BD85eFdlNZnYvhtEQBCeeNGaNxOSFN\n Z4sg==","X-Forwarded-Encrypted":"i=1;\n AJvYcCVF4QyeQqmdd2fFfNykG8x2zJZ8kFtPeUzXn7rh7Ln2Fj/TU//FlyV7FY9F66RRwngDY4DsLEE1qbAGsw==@gcc.gnu.org","X-Gm-Message-State":"AOJu0Yw+gO5tMSNI9m5gETSX8SXxCMaS6XE8XHinKt4xTxnqs21Lp7gQ\n rsLXuymx8PQ3pGGh1ozsuxyg5HRdZEjZ1dHQ/NefdMZFHVb6yfuADVXJsPDXLWUNg8fOHyOI3Q7\n Zjc0W7hU2XVnA3tgnyVdYFKA4qngUHt6S8W3fp/q8ZgRPNV9zzjTxhQF1vZz03fAaCnacUw==","X-Gm-Gg":"AeBDiev0HAQ91N8I450Wd1XXaMOSt9esccwLcmpJG24qWG2Oplc+ICCWRmK+kr/SyzV\n Oh38BGelCHCO2zA45R8hJe+6r9/8MFRajGZHg8dDlEQ7ZLGHmTDujpSSOOZD0kbXsWeaHj6ndkf\n t4PgxrzDlA5xnd1ZEhxzrMaFiry8tTX5fKSZP3/7HZPgAwA5mUIKrGqnwTdB5w0VF+Rx1tHmhXa\n Ot6IssrTDMMTSz2Hbv7XX+afs0f47lK6KaN64ozX6Y0Kx6bnA52fbBgzTh7tfHYJ+emdv63llXF\n Ps88bi7MUUhwnVaKphuBSUckO7RrudKLygOecZGMW504x48SbEAikrwWUvr7qxCqclpITGpdM5K\n JjbK6MPwefYZduGqBLaE/aFvp9bvsnfh5Dc3gNfEKdtHCCWT2h0vJcbN6ZwqB4YGsX3nHjctHcp\n 1amgaTJ2T8fKIyxEZ2T1VjATcwekRW/2s=","X-Received":["by 2002:a05:620a:4892:b0:8cf:cee2:e400 with SMTP id\n af79cd13be357-8d41b8df635mr1920046585a.8.1775493527989;\n Mon, 06 Apr 2026 09:38:47 -0700 (PDT)","by 2002:a05:620a:4892:b0:8cf:cee2:e400 with SMTP id\n af79cd13be357-8d41b8df635mr1920042485a.8.1775493527448;\n Mon, 06 Apr 2026 09:38:47 -0700 (PDT)"],"Message-ID":"<1986162f-dd7a-4724-a5cb-4443de377626@redhat.com>","Date":"Mon, 6 Apr 2026 12:38:45 -0400","MIME-Version":"1.0","User-Agent":"Mozilla Thunderbird","Subject":"Re: [PATCH] c++/modules: Fix entry-point detection for recursive\n clusters [PR118630]","To":"Nathaniel Shead <nathanieloshead@gmail.com>, gcc-patches@gcc.gnu.org","References":"<adKJls2SKRnQY004@Thaum.localdomain>","From":"Jason Merrill <jason@redhat.com>","In-Reply-To":"<adKJls2SKRnQY004@Thaum.localdomain>","X-Mimecast-Spam-Score":"0","X-Mimecast-MFC-PROC-ID":"2_5Cfk4MqFz72mJeqnojZkLkU2AW5aBNcIeolDfq3YA_1775493529","X-Mimecast-Originator":"redhat.com","Content-Language":"en-US","Content-Type":"text/plain; charset=UTF-8; format=flowed","Content-Transfer-Encoding":"7bit","X-BeenThere":"gcc-patches@gcc.gnu.org","X-Mailman-Version":"2.1.30","Precedence":"list","List-Id":"Gcc-patches mailing list <gcc-patches.gcc.gnu.org>","List-Unsubscribe":"<https://gcc.gnu.org/mailman/options/gcc-patches>,\n <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe>","List-Archive":"<https://gcc.gnu.org/pipermail/gcc-patches/>","List-Post":"<mailto:gcc-patches@gcc.gnu.org>","List-Help":"<mailto:gcc-patches-request@gcc.gnu.org?subject=help>","List-Subscribe":"<https://gcc.gnu.org/mailman/listinfo/gcc-patches>,\n <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe>","Errors-To":"gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org"}}]