public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "nishuangcheng at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/110730] New: STL internal allocation/deallocation might lead to core dump in the use of header units of the modules feature
Date: Wed, 19 Jul 2023 06:43:29 +0000	[thread overview]
Message-ID: <bug-110730-4@http.gcc.gnu.org/bugzilla/> (raw)

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	other threads:[~2023-07-19  6:43 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-19  6:43 nishuangcheng at gmail dot com [this message]
2024-03-06 18:01 ` [Bug c++/110730] " ppalka at gcc dot gnu.org
2024-03-06 18:02 ` ppalka at gcc dot gnu.org
2024-03-06 20:06 ` ppalka at gcc dot gnu.org
2024-03-07 21:24 ` cvs-commit at gcc dot gnu.org
2024-03-07 21:25 ` ppalka at gcc dot gnu.org
2024-03-26 11:39 ` nishuangcheng at gmail dot com

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-110730-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).