From patchwork Sun Apr 5 16:11:02 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathaniel Shead X-Patchwork-Id: 132716 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [127.0.0.1]) by sourceware.org (Postfix) with ESMTP id E2D9B4BA23C3 for ; Sun, 5 Apr 2026 16:11:49 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E2D9B4BA23C3 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b=o1NdanEp X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pj1-f41.google.com (mail-pj1-f41.google.com [209.85.216.41]) by sourceware.org (Postfix) with ESMTPS id 568814BA2E1C for ; Sun, 5 Apr 2026 16:11:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 568814BA2E1C Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 568814BA2E1C Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=209.85.216.41 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1775405470; cv=none; b=teZslQ+FDiN5t+8eV0jRAdYc7+emS6lZN2GBi20hf7LxaUc7Yq19QShbTi77EXONICY+Lm21zO0RxwKdEjuw/pwSUz2XsVVUO+m33z+2jLpGs7n6enrJRl/ppKUI2Dzcs1yBfDQ5EfH5hipgaXXL4ulCNBucQr/7knuSmULH5Do= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1775405470; c=relaxed/simple; bh=C/mGAXcOJRFFxXvbG1g2ecYVdEg1TdLKZAnz3VAjsyg=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=m1Ys4w3TsUJSyY3ktW1MxtKEKuegzU071YyaiqV4UxV/DcQa7ghT7MmEX0tUWCe4uGSWSihIZA+e9uhWrhPVQgMsJHxnxgj3H5VgB/uVZpgJIYk7HKrrPfx7/lmX10pUxWJutd6NXI5oCqi4vNnVpmueYu7B54124OQ6qqoVXqo= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 568814BA2E1C Received: by mail-pj1-f41.google.com with SMTP id 98e67ed59e1d1-35448ca4689so627539a91.0 for ; Sun, 05 Apr 2026 09:11:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1775405469; x=1776010269; darn=gcc.gnu.org; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :from:to:cc:subject:date:message-id:reply-to; bh=lhSQvhB42OUOvcE58WuT6BynyGG+R/iG7fZeeKh39XE=; b=o1NdanEpAnBx/8YN5dH/ZQlzE7hPo2RyM/bzjvyBpHt/b9n8duXMP/R3Upv3ERleWi pNEjpARHieca6FriOa/rBJL62rAlWP1rwIRqb8yq3aII8b5nGX/Ac9V2dGFkXhq9Yu48 6Kx4UT8zWchIJFSHcpL7UkHHwdSNlT8tJylMs2C8V6sxkYovoF8iNflQqxbu1UquFeVz CBd0eNNfP/yLWGCV5/2m9K3fhyOPEreEvzRcwN5ZetZZIOqnQDWZHHeUbTWDySADltRG 8rEhVpBYIP4SJ9KdMl5zPu/GdntgRm+iYy+1vTOGDWcNL9r7zttlgNh7ozK0/MVEocSi 9a+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775405469; x=1776010269; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=lhSQvhB42OUOvcE58WuT6BynyGG+R/iG7fZeeKh39XE=; b=VQOiASS8oWHX7yaUc7HyfpgpoLMuNSPNisAI9+b5x9Z07B3NNVVuKfPRI8Jn8NmC3J Ks140f3cJdnZxN61MKwgn4Iz7fZ4qNNdfaKf4wJjvxVxfTh2vIo6RpxP36xNTS8l/qZ5 NB5oWw0RgU7ZdlJ60IqOm6oF2rxFVciwuDk65f7GV/Uexy0YiC/lyBdX3a/X+EuXyQVy kUgLZ4HLaiocOSqdFwjnb9FXPm6Fh+6asU1z7wa6kkHqdzAObiMqSqbhAfGw5zJA9Vaz evNZLMtth6aQjgJG/hohYmIOA2hxwh9oub0EwOpPv0SrPXXYT6LIcaEe5Ub8BmHLKyD9 cGQA== X-Gm-Message-State: AOJu0YxUSJ+J1c6SwWB81E+Ln4m1uJWB6ia+7Vu4P8lZITuIgxgZPsuS 9+SXRts71BawrddITZtuE/ni0C5mlsIqjZIRcvuSsPdRPZgXHsHxYFwFJzY0KA== X-Gm-Gg: AeBDieu5/bv8NWvz+BbURXscC+pQRhpql2oWppstnPv9q8gn5IvudRlBe3nPANHT0Ur u+lycD40tuz2nntuqfWHeq4qotwDP3yDkzEjbKvPsSBKFtuFHya6qqw4oqxOe2OAJ0ASuw//VfA Zcg2lT9Pc1dn30WiWwOWXCVM2V8rymx1+9dtyymJb/zhtRthAIxWVHnDdejaQ8zKofJvl0ddJbX yxu2lubj9hvr7wftY0HxfEakPcje7EBtUkv6ku4x5u65ZkvE4YmdzNJSyk6gBFBhJ0w96acuiPB GnC9Tw19q6+LnYpLsZBB19+7QST6BfjiTSwX1qiTxNb3pg4+ap+hVc7abG+HuoXxqmnXU2vh5KG b8v0okmpV4sZ7GM8yq6vS3w1St3/QejCpoSWWKAtX0usKLyUUAUectCQ4fJcfoet53aTAHmt5mq c0XbP66MX7GxuYG9/bG0qtKMVVuTS0RFfR49DaRDWI75GL X-Received: by 2002:a17:90b:2fc4:b0:359:8e93:4fd6 with SMTP id 98e67ed59e1d1-35de6971783mr5314086a91.4.1775405469164; Sun, 05 Apr 2026 09:11:09 -0700 (PDT) Received: from Thaum.localdomain ([163.53.146.3]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-c76c6491157sm9223384a12.9.2026.04.05.09.11.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Apr 2026 09:11:08 -0700 (PDT) Date: Mon, 6 Apr 2026 02:11:02 +1000 From: Nathaniel Shead To: gcc-patches@gcc.gnu.org Cc: Jason Merrill Subject: [PATCH] c++/modules: Fix entry-point detection for recursive clusters [PR118630] Message-ID: MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED, 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 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 Bootstrapped and regtested on x86_64-pc-linux-gnu, OK for trunk/15? -- >8 -- In r15-4861-g4a99443c5dd9a235022652ba0fb143c6370ea99d we added support to handle recursive dependency clusters, where we need to find the "entry" dependency that all other entities will hook off to ensure that we stream merge keys in the correct order on read-in. The logic I'd used to track the entry bit was not completely correct however, leading to assertion failures in 'sort_cluster' where we found that entities were not marked maybe_recursive when they should have been, or multiple entities were marked as the entry point. Consider a cycle of three entities in a cluster, 'A', 'B', and 'C', where 'A' is the entry point. By definition we walk into 'A' first, and find one of the other entities, 'B'. The old logic marked 'A' as the entry and 'B' as maybe-recursive; so far this is correct. But then if we walk into 'B' and find 'C' is maybe-recursive, the old logic would mark 'B' as the entry point (again!). And likewise when we walk into 'C' and find 'A'. So we would end up with three entry points. Similar issues could happen with other arrangements of dependencies. Instead, by aggressively marking everything we see as maybe-recursive, and only marking an entry point if nothing we see is maybe-recursive, we avoid this issue. We should only be able to discover these other entities through the entry point (A) and so this 'flood fill' behaviour should ensure that all entities are correctly marked maybe-recursive, and only A is marked as an entry-point. PR c++/118630 gcc/cp/ChangeLog: * module.cc (depset::hash::add_dependency): Correct entry point corection for recursive clusters. gcc/testsuite/ChangeLog: * g++.dg/modules/late-ret-5.h: New test. * g++.dg/modules/late-ret-5_a.H: New test. * g++.dg/modules/late-ret-5_b.C: New test. Signed-off-by: Nathaniel Shead --- gcc/cp/module.cc | 5 +++-- gcc/testsuite/g++.dg/modules/late-ret-5.h | 16 ++++++++++++++++ gcc/testsuite/g++.dg/modules/late-ret-5_a.H | 6 ++++++ gcc/testsuite/g++.dg/modules/late-ret-5_b.C | 6 ++++++ 4 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/g++.dg/modules/late-ret-5.h create mode 100644 gcc/testsuite/g++.dg/modules/late-ret-5_a.H create mode 100644 gcc/testsuite/g++.dg/modules/late-ret-5_b.C diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc index 6958388e454..5828748a3e6 100644 --- a/gcc/cp/module.cc +++ b/gcc/cp/module.cc @@ -14855,9 +14855,10 @@ depset::hash::add_dependency (depset *dep) details. */ if (writing_merge_key) { - dep->set_flag_bit (); - if (!current->is_maybe_recursive ()) + if (!dep->is_maybe_recursive () && !current->is_maybe_recursive ()) current->set_flag_bit (); + dep->set_flag_bit (); + current->set_flag_bit (); } if (dep->is_unreached ()) diff --git a/gcc/testsuite/g++.dg/modules/late-ret-5.h b/gcc/testsuite/g++.dg/modules/late-ret-5.h new file mode 100644 index 00000000000..6f14d18e757 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/late-ret-5.h @@ -0,0 +1,16 @@ +// PR c++/118630 + +namespace test1 { + template decltype([]{}) a(); +} + +namespace test2 { + template struct invoke_result {}; + template struct foo {}; + + template + auto b(T&& arg) -> foo> { + invoke_result a; + return {}; + } +} diff --git a/gcc/testsuite/g++.dg/modules/late-ret-5_a.H b/gcc/testsuite/g++.dg/modules/late-ret-5_a.H new file mode 100644 index 00000000000..b39b1d4529f --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/late-ret-5_a.H @@ -0,0 +1,6 @@ +// PR c++/118630 +// { dg-do compile { target c++20 } } +// { dg-additional-options "-fmodule-header" } +// { dg-module-cmi {} } + +#include "late-ret-5.h" diff --git a/gcc/testsuite/g++.dg/modules/late-ret-5_b.C b/gcc/testsuite/g++.dg/modules/late-ret-5_b.C new file mode 100644 index 00000000000..d22d7638127 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/late-ret-5_b.C @@ -0,0 +1,6 @@ +// PR c++/118630 +// { dg-do compile { target c++20 } } +// { dg-additional-options "-fmodules -fno-module-lazy" } + +#include "late-ret-5.h" +import "late-ret-5_a.H";