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

            Bug ID: 100689
           Summary: internal compiler error: Segmentation fault when using
                    modules and -g
           Product: gcc
           Version: 11.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ma30002000 at yahoo dot de
  Target Milestone: ---

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.

Reply via email to