Bug 100689 - [modules] internal compiler error: Segmentation fault when using modules and -g
Summary: [modules] internal compiler error: Segmentation fault when using modules and -g
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 11.1.0
: P3 normal
Target Milestone: 14.0
Assignee: Nathaniel Shead
URL:
Keywords: ice-on-valid-code
Depends on:
Blocks: c++-modules
  Show dependency tree / graph
 
Reported: 2021-05-20 02:52 UTC by Matthias Schneider
Modified: 2024-02-11 14:11 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Matthias Schneider 2021-05-20 02:52:35 UTC
When compile file files exp.cpp and imp.cpp with the following contents:
------------ exp.cpp ----------
module;

#include <string>

export module mod;

export std::string F() { return "test"; }
-------------------------------
------------ imp.cpp ----------
#include <span>
#include <string>
#include <cstdint>

import mod;

constexpr void
ToHexInt(uint8_t value, char& dst) {
    if (value <= 9)
	dst = static_cast<char>('0' + value);
    if (value >= 0xa && value <= 0xf)
	dst = static_cast<char>('a' + (value - 0x0a));
}

template <class DestT = std::string>
inline DestT
ToHexString(const std::span<const uint8_t>& value) {
    DestT output;
    output.resize(value.size() * 2);
    uint8_t i;
    ToHexInt(i, output[0]);
    return output;
}

int main() {
    uint8_t a[2];
    ToHexString(a);
}
-------------------------------
with the following compiler command lines:
/usr/bin/g++-11      -g  -fmodules-ts  -std=gnu++2a -o exp.cpp.o -c exp.cpp
/usr/bin/g++-11      -g  -fmodules-ts  -std=gnu++2a -o imp.cpp.o -c imp.cpp

I get the following error on compilation of imp.cpp:
-------------------------------
In file included from /usr/include/c++/11/string:38,
                 from exp.cpp:3,
of module mod, imported at imp.cpp:5:
/usr/include/c++/11/bits/basic_string.h:1045:9: internal compiler error: Segmentation fault
 1045 |         __glibcxx_assert(__pos <= size());
      |         ^~~~~~~~~~~~~~~~
0xe30681 internal_error(char const*, ...)
	???:0
0x9d6c83 module_state::mangle(bool)
	???:0
0xf628a7 mangle_decl(tree_node*)
	???:0
0x1487939 symbol_table::finalize_compilation_unit()
	???:0
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See <file:///usr/share/doc/gcc-11/README.Bugs> for instructions.
-------------------------------
If I do not specify "-g" the compilation concludes successfully.
Comment 1 Nathaniel Shead 2024-02-11 14:11:39 UTC
Fixed for GCC 14 with r14-8350-gaffef534b03355.