From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id E0406385842F; Fri, 1 Mar 2024 22:24:41 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E0406385842F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1709331881; bh=NuwqIyK136ECrbvleuafE5icNMzvD4VfTUFjUxRlg1g=; h=From:To:Subject:Date:In-Reply-To:References:From; b=niLQLdk2yR9vBIr88nHYXuruLLs3TCgo2Ev9ENAz/IoCwyZbQn+3ONlhMOzH4/zUe JxdHj2J6t3gq0Eh4QMU1pNtCdfC2ZeEVx4W6tQm2Ts9cMtsNyYhAO6/ziyK0UgEDf4 v47URo9bJL7wOpd2wbnalpaVos5nDErIYYhzSAYw= From: "cvs-commit at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/106009] [modules] internal compiler error: in import_entity_index with templated local enum in header unit Date: Fri, 01 Mar 2024 22:24:38 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 13.0 X-Bugzilla-Keywords: ice-checking, ice-on-valid-code X-Bugzilla-Severity: normal X-Bugzilla-Who: cvs-commit at gcc dot gnu.org X-Bugzilla-Status: ASSIGNED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: ppalka at gcc dot gnu.org X-Bugzilla-Target-Milestone: 14.0 X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D106009 --- Comment #4 from GCC Commits --- The master branch has been updated by Patrick Palka : https://gcc.gnu.org/g:574fd1f17f100c7c355ad26bc525ab5a3386bb2d commit r14-9268-g574fd1f17f100c7c355ad26bc525ab5a3386bb2d Author: Patrick Palka Date: Fri Mar 1 17:24:15 2024 -0500 c++/modules: depending local enums [PR104919, PR106009] For local enums defined in a non-template function or a function templa= te instantiation it seems we neglect to make the function depend on the en= um definition (which modules considers logically separate), which ultimate= ly causes the enum definition to not be properly streamed before uses within the function definition are streamed. The code responsible for noting such dependencies is gcc/cp/module.cc @@ -8784,17 +8784,6 @@ trees_out::decl_node (tree decl, walk_kind ref) depset *dep =3D NULL; if (streaming_p ()) dep =3D dep_hash->find_dependency (decl); ! else if (TREE_CODE (ctx) !=3D FUNCTION_DECL ! || TREE_CODE (decl) =3D=3D TEMPLATE_DECL ! || (dep_hash->sneakoscope && DECL_IMPLICIT_TYPEDEF_P (decl)) ! || (DECL_LANG_SPECIFIC (decl) ! && DECL_MODULE_IMPORT_P (decl))) ! { ! auto kind =3D (TREE_CODE (decl) =3D=3D NAMESPACE_DECL ! && !DECL_NAMESPACE_ALIAS (decl) ! ? depset::EK_NAMESPACE : depset::EK_DECL); ! dep =3D dep_hash->add_dependency (decl, kind); ! } if (!dep) { and the condition there notably excludes local TYPE_DECLs from a non-template-pattern function (when streaming a template pattern we'll see be dealing with the corresponding TEMPLATE_DECL of the local TYPE_DECL here, so we'll add the dependency). Local classes on the other hand seem to work properly, but perhaps by accident: with a local class we end up making the function depend on the injected-class-name of the local class rather than the local class as a whole because the injected-class-name satisfies the criteria (since its context is the local class, not the function). The 'sneakoscope' flag is set when walking a function declaration and its purpose seems to be to catch a local type that escapes the function via a deduced return type (so called voldemort types) and note a dependency on them. But there seems to be no reason to restrict this behavior to voldemort types, and indeed consistently noting the depende= ncy for all local types fixes these PRs (almost). So this patch gets rid of this flag and enables the dependency tracking unconditionally. This was nearly enough to make things work, except we now ran into issues with the local TYPE_/CONST_DECL copies from the pre-gimplified version of a constexpr function body during streaming. Rather than making modules cope with this, it occurred to me that we don't need to make copies of local types when saving the pre-gimplified body (and when making further copies thereof); only VAR_DECLs etc need to be copied (so that we don't conflate local variables from different recursive calls to the same function during constexpr evaluation). So this patch adjusts copy_fn accordingly. PR c++/104919 PR c++/106009 gcc/cp/ChangeLog: * module.cc (depset::hash::sneakoscope): Remove. (trees_out::decl_node): Always add a dependency on a local type. (depset::hash::find_dependencies): Remove sneakoscope stuff. gcc/ChangeLog: * tree-inline.cc (remap_decl): Handle copy_decl returning the original decl. (remap_decls): Handle remap_decl returning the original decl. (copy_fn): Adjust copy_decl callback to skip TYPE_DECL and CONST_DECL. gcc/testsuite/ChangeLog: * g++.dg/modules/tdef-7.h: Remove outdated comment. * g++.dg/modules/tdef-7_b.C: Don't expect two TYPE_DECLs. * g++.dg/modules/enum-13_a.C: New test. * g++.dg/modules/enum-13_b.C: New test.=