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

            Bug ID: 110730
           Summary: STL internal allocation/deallocation might lead to
                    core dump in the use of header units of the modules
                    feature
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: nishuangcheng at gmail dot com
  Target Milestone: ---

---
the exact version of GCC: 14.0.0
---
the system type: Linux, Ubuntu 22.04.2 LTS, x86_64
---
the options given when GCC was configured/built:
--enable-default-pie --enable-host-pie --enable-host-shared
--enable-languages=default,go --enable-threads=posix
--with-multilib-list=m32,m64,mx32
---
the complete command line that triggers the bug and the output:
###test case1###
$ cat module-test.cpp 
import <filesystem>;

int main(int argc, char **argv) {
  return !std::filesystem::exists(argc == 1 ? std::filesystem::current_path()
                                            : argv[1]);
}

$ g++ -std=c++23 -fmodules-ts -Wall -Wextra -x c++-system-header filesystem -x
c++ module-test.cpp -o module-test

$ ./module-test # error
free(): invalid pointer
Aborted (core dumped)

$ ./module-test existing_file # ok

$ echo $?
0

$ ./module-test nonexisting_file # ok

$ echo $?
1

###end of test case1###

###test case2###
$ cat module-test.cpp 
import <filesystem>;
import <iostream>;

int main() {
  std::cout << "PWD: " << std::filesystem::current_path() << std::endl;
  return 0;
}

$ g++ -std=c++23 -fmodules-ts -Wall -Wextra -x c++-system-header filesystem
iostream -x c++ module-test.cpp -o module-test

$ ./module-test # changing the importing order produces the same result
terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc
Aborted (core dumped)
###end of test case2###
---
It seems that this is not a mere issue of multiple header-unit compilation
mentioned in https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99227, since there is
only one header unit in test case1.
Besides, this is a runtime issue instead of a compile-time one. The problem is
probably related to the <filesystem> header unit. Thus, I only include its
preprocessed file in my attachments.

Reply via email to