Bug 109953 - [c++modules] segmentation fault with import "functional" during program execution
Summary: [c++modules] segmentation fault with import "functional" during program execu...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 14.0
: P3 normal
Target Milestone: 14.0
Assignee: Not yet assigned to anyone
URL:
Keywords: wrong-code
Depends on:
Blocks: 110894
  Show dependency treegraph
 
Reported: 2023-05-24 09:31 UTC by Saifi Khan
Modified: 2024-02-16 00:27 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2023-05-24 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Saifi Khan 2023-05-24 09:31:09 UTC
environment GNU/Linux 6.3.3 gcc 14.0.0 glibc 2.37-3

command 'g++ -std=c++23 -v -g3 -Wall -fmodules-ts'

Here is the program

import "iostream";
import "functional";
import "string_view";

auto test (std::string_view sv) -> void {

      std::cout << sv.substr (std::size_t {0}, std::size_t {8})
                << '\n';
}

auto main () -> int {

     test ("Free Software Community");

return 0;
}

When the program is executed, it encounters a segmentation fault.

The stack trace is as follows

Program received signal SIGSEGV, Segmentation fault.
0x0000555555555344 in std::min<unsigned long> (__a=@0x7fffffffe0d8: 8, __b=@0x7fffffffe0f8: 23) at /opt/gcc/include/c++/14.0.0/bits/stl_algobase.h:238
238	      if (__b < __a)
(gdb) bt
#0  0x0000555555555344 in std::min<unsigned long> (__a=@0x7fffffffe0d8: 8, __b=@0x7fffffffe0f8: 23) at /opt/gcc/include/c++/14.0.0/bits/stl_algobase.h:238
#1  0x00005555555553bf in std::basic_string_view<char, std::char_traits<char> >::substr (this=0x7fffffffe130, __pos=0, __n=8)
    at /opt/gcc/include/c++/14.0.0/string_view:336
#2  0x00005555555551c4 in test (sv="Free Software Community") at str_view_01.cc:10
#3  0x0000555555555230 in main () at str_view_01.cc:16
(gdb) 


NOTE
when the line 'import "functional";' is commented out and the program is re-compiled. It executes and prints the expected result "Free Sof".
Comment 1 Jonathan Wakely 2023-05-24 09:58:22 UTC
Confirmed.

N.B. to compile the program you first need to do:

for i in iostream functional string_view ; do
  g++ -c -std=c++23 -g3 -fmodules-ts -fmodule-only -x c++-system-header $i
done
Comment 2 Nathaniel Shead 2024-02-16 00:27:30 UTC
Looks to be fixed on GCC 14 trunk.