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

            Bug ID: 118904
           Summary: [modules] ICE with std::source_location::current in
                    inline function
           Product: gcc
           Version: 14.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: nshead at gcc dot gnu.org
            Blocks: 103524
  Target Milestone: ---

The following sample ICEs on current trunk:

  module;
  #include <source_location>
  export module M;
  inline void foo() {
    std::source_location::current();
  }

g++ -fmodules -std=c++20 -S test.cpp

test.cpp:3:8: internal compiler error: in tree_node, at cp/module.cc:9759
    3 | export module M;
      |        ^~~~~~
0x3ca6deb internal_error(char const*, ...)
        ../../gcc/gcc/diagnostic-global-context.cc:517
0x3c720c0 fancy_abort(char const*, int, char const*)
        ../../gcc/gcc/diagnostic.cc:1722
0x111219b tree_node
        ../../gcc/gcc/cp/module.cc:9759
0x11023bb core_vals
        ../../gcc/gcc/cp/module.cc:6242
0x1106f74 tree_node_vals
        ../../gcc/gcc/cp/module.cc:7492
0x1110fbf tree_value
        ../../gcc/gcc/cp/module.cc:9476
0x1112201 tree_node
        ../../gcc/gcc/cp/module.cc:9779
0x1103eb4 core_vals
        ../../gcc/gcc/cp/module.cc:6670
0x1106f74 tree_node_vals
        ../../gcc/gcc/cp/module.cc:7492
0x1110fbf tree_value
        ../../gcc/gcc/cp/module.cc:9476
0x1112201 tree_node
        ../../gcc/gcc/cp/module.cc:9779
0x11023bb core_vals
        ../../gcc/gcc/cp/module.cc:6242
0x1106f74 tree_node_vals
        ../../gcc/gcc/cp/module.cc:7492
0x1110fbf tree_value
        ../../gcc/gcc/cp/module.cc:9476
0x1112201 tree_node
        ../../gcc/gcc/cp/module.cc:9779
0x11023bb core_vals
        ../../gcc/gcc/cp/module.cc:6242
0x1106f74 tree_node_vals
        ../../gcc/gcc/cp/module.cc:7492
0x1110fbf tree_value
        ../../gcc/gcc/cp/module.cc:9476
0x1112201 tree_node
        ../../gcc/gcc/cp/module.cc:9779
0x11023bb core_vals
        ../../gcc/gcc/cp/module.cc:6242
Please submit a full bug report, with preprocessed source (by using
-freport-bug).
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.


The cause of the ICE is that the implicit VAR_DECL created within
'fold_builtin_source_location' has no 'DECL_CONTEXT', which the modules
implementation generally relies on to stream correctly.

Disabling this checking assertion exposes other issues, too; in particular,
similarly to PR98893 the name of the backing for the source location var is
created by incrementing a global 'source_location_id' counter, which doesn't
work properly across modules causing clashes.  We'll need to come up with a way
to ensure that we properly emit the declarations; a possible testcase is

  // header.hpp
  #include <source_location>
  inline auto foo() {
    return std::source_location::current();
  }

  // main.cpp
  import "header.hpp";
  int main() {
    auto a = foo().file_name();
    auto b = std::source_location::current().file_name();
    return !(a[0] == b[0]);
  }


Referenced Bugs:

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

Reply via email to