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

            Bug ID: 122804
           Summary: [modules] segfault when importing std and using
                    std::print in debug mode
           Product: gcc
           Version: 15.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jan.kuhlmann at proton dot me
  Target Milestone: ---

Created attachment 62879
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=62879&action=edit
*.ii output from -save-temps

GCC used here is 15.2.1 on linux. Same for the stdlib. Linker is ld, but
lld/mold produce the same effect.

Conditions to trigger the segfault:
- compile in debug mode (-O3 does not trigger a segfault)
- use import std
- use std::print

Minimal C++ for reproduction:
// src/main.cpp
import std;
int main() {
    std::println("hello");
}

The full command produced by CMake+Ninja, followed by the segfault:
/usr/bin/g++   -g -std=gnu++23 -save-temps -MD -MT
CMakeFiles/project.dir/src/main.cpp.o -MF
CMakeFiles/project.dir/src/main.cpp.o.d -fmodules-ts
-fmodule-mapper=CMakeFiles/project.dir/src/main.cpp.o.modmap -MD
-fdeps-format=p1689r5 -x c++ -o CMakeFiles/project.dir/src/main.cpp.o -c
/home/jan/TESTING/src/main.cpp

Segmentation fault
    4 | }
      | ^
0x1819ede diagnostic_context::diagnostic_impl(rich_location*,
diagnostic_metadata const*, diagnostic_option_id, char const*, __va_list_tag
(*) [1], diagnostic_t)
        ???:0
0x17da9ff internal_error(char const*, ...)
        ???:0
0x181b539 pp_string(pretty_printer*, char const*)
        ???:0
0x2276232 pretty_printer::format(text_info&)
        ???:0
0x181a47c diagnostic_context::report_diagnostic(diagnostic_info*)
        ???:0
0x1819ede diagnostic_context::diagnostic_impl(rich_location*,
diagnostic_metadata const*, diagnostic_option_id, char const*, __va_list_tag
(*) [1], diagnostic_t)
        ???:0
0x708a97 fatal_error(unsigned long, char const*, ...)
        ???:0

Interestingly, not using -save-temps may be slightly more insightful than a
segfault during linking with ld; complaining about undefined references to
std::span<char, 18446744073709551615ul>::__v<12ul>. I have attached the *.ii
regardless.
  • [Bug c++/122804] New: [modules]... jan.kuhlmann at proton dot me via Gcc-bugs

Reply via email to