public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/116382] New: [modules] Importing NTTP of template type causes recursive lazy load
@ 2024-08-15 12:10 nshead at gcc dot gnu.org
  2024-08-20  7:14 ` [Bug c++/116382] " cvs-commit at gcc dot gnu.org
  2024-08-20  7:16 ` nshead at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: nshead at gcc dot gnu.org @ 2024-08-15 12:10 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116382

            Bug ID: 116382
           Summary: [modules] Importing NTTP of template type causes
                    recursive lazy load
           Product: gcc
           Version: 15.0
            Status: UNCONFIRMED
          Keywords: rejects-valid
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: nshead at gcc dot gnu.org
          Reporter: nshead at gcc dot gnu.org
            Blocks: 103524
  Target Milestone: ---

Consider:

  // a.cpp
  module m:a;
  template <typename> struct X {};
  template <X<int> nttp> struct index {};
  template struct index<{}>;

  // m.cpp
  export module m;
  import :a;


With 'g++ -fmodules-ts -std=c++20 -S a.cpp m.cpp':

m.C:2:11: error: recursive lazy load
    2 | import :a;
      |           ^
m.C:2:11: fatal error: failed to load pendings for ‘::X’
compilation terminated.


This error occurs even with '-fno-module-lazy'.  The root cause seems to be the
following logic for streaming in NTTPs in 'trees_in::tree_node':

    case tt_nttp_var:
      /* An NTTP object. */
      {
        tree init = tree_node ();
        tree name = tree_node ();
        if (!get_overrun ())
          {
            res = get_template_parm_object (init, name);
            int tag = insert (res);
            dump (dumper::TREE)
              && dump ("Created nttp object:%d %N", tag, name);
          }
      }
      break;


The call to 'get_template_parm_object' calls 'cp_finish_decl' which eventually
ends up performing name lookup on the as-yet unstreamed '::X' when processing
the initialiser, resulting in a call to 'lazy_load_pendings' which cannot be
done during streaming.


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103524
[Bug 103524] [meta-bug] modules issue

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug c++/116382] [modules] Importing NTTP of template type causes recursive lazy load
  2024-08-15 12:10 [Bug c++/116382] New: [modules] Importing NTTP of template type causes recursive lazy load nshead at gcc dot gnu.org
@ 2024-08-20  7:14 ` cvs-commit at gcc dot gnu.org
  2024-08-20  7:16 ` nshead at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-08-20  7:14 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116382

--- Comment #1 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Nathaniel Shead <nshead@gcc.gnu.org>:

https://gcc.gnu.org/g:0b7904e274fbd6a736d63c0fed28ea32f9cb5997

commit r15-3031-g0b7904e274fbd6a736d63c0fed28ea32f9cb5997
Author: Nathaniel Shead <nathanieloshead@gmail.com>
Date:   Fri Aug 16 15:06:33 2024 +1000

    c++/modules: Avoid rechecking initializers when streaming NTTPs [PR116382]

    When reading an NTTP we call get_template_parm_object which delegates
    setting of DECL_INITIAL to the general cp_finish_decl procedure, which
    calls check_initializer to validate and record it.

    Apart from being unnecessary (it must have already been validated by the
    writing module), this also causes errors in cases like the linked PR, as
    validating may end up needing to call lazy_load_pendings to determine
    any specialisations that may exist which violates assumptions of the
    modules streaming code.

    This patch works around the issue by adding a flag to
    get_template_parm_object to disable these checks when not needed.

            PR c++/116382

    gcc/cp/ChangeLog:

            * cp-tree.h (get_template_parm_object): Add check_init param.
            * module.cc (trees_in::tree_node): Pass check_init=false when
            building NTTPs.
            * pt.cc (get_template_parm_object): Prevent cp_finish_decl from
            validating the initializer when check_init=false.

    gcc/testsuite/ChangeLog:

            * g++.dg/modules/tpl-nttp-1_a.C: New test.
            * g++.dg/modules/tpl-nttp-1_b.C: New test.

    Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
    Reviewed-by: Jason Merrill <jason@redhat.com>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug c++/116382] [modules] Importing NTTP of template type causes recursive lazy load
  2024-08-15 12:10 [Bug c++/116382] New: [modules] Importing NTTP of template type causes recursive lazy load nshead at gcc dot gnu.org
  2024-08-20  7:14 ` [Bug c++/116382] " cvs-commit at gcc dot gnu.org
@ 2024-08-20  7:16 ` nshead at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: nshead at gcc dot gnu.org @ 2024-08-20  7:16 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116382

Nathaniel Shead <nshead at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |15.0
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |FIXED

--- Comment #2 from Nathaniel Shead <nshead at gcc dot gnu.org> ---
Fixed for GCC 15.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-08-20  7:16 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-08-15 12:10 [Bug c++/116382] New: [modules] Importing NTTP of template type causes recursive lazy load nshead at gcc dot gnu.org
2024-08-20  7:14 ` [Bug c++/116382] " cvs-commit at gcc dot gnu.org
2024-08-20  7:16 ` nshead at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).