From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 205003858407; Mon, 31 Jul 2023 15:02:25 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 205003858407 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1690815745; bh=BVABCIch6GlQDvPJvGgmRjmf3ZSXTfT7yPffo9AN48M=; h=From:To:Subject:Date:From; b=j8jYPp9KDma5tQuGWtnEj8JuPv7KIH+MvOQurCqt6AiIh78d5dAH1WJWkeGETjHso 2XFO0iR8hfMd/01nKyCnIDYKyR7iXY8gkpiT0lcIIlfY7y3nsrfCeJBmFXzMA0imC0 QxMkd8/r/v92rfZRXd1goe+0YKojDDbLYVhQ4JS4= From: "headch at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/110861] New: Bad codegen leading to runtime segfault when mixing import and #include Date: Mon, 31 Jul 2023 15:02:24 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 13.2.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: headch at gmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D110861 Bug ID: 110861 Summary: Bad codegen leading to runtime segfault when mixing import and #include Product: gcc Version: 13.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: headch at gmail dot com Target Milestone: --- $ g++-13 --version g++-13 (Gentoo 13.2.0 p3) 13.2.0 Copyright (C) 2023 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. $ cat hello.cpp #include import ; void f(std::string_view sv) { std::cout << sv; } int main() { f("hello\n"); } $ g++-13 -O1 -Wall -Wextra -c -std=3Dc++20 -x c++-system-header -fmodules-ts -fmodule-header=3Dsystem iostream $ g++-13 -std=3Dc++20 -O1 -Wall -Wextra -fmodules-ts -ohello hello.cpp In file included from /usr/lib/gcc/x86_64-pc-linux-gnu/13/include/g++-v13/bits/basic_string.h:47, from /usr/lib/gcc/x86_64-pc-linux-gnu/13/include/g++-v13/string:54, from /usr/lib/gcc/x86_64-pc-linux-gnu/13/include/g++-v13/bits/locale_classes.h:4= 0, from /usr/lib/gcc/x86_64-pc-linux-gnu/13/include/g++-v13/bits/ios_base.h:41, from /usr/lib/gcc/x86_64-pc-linux-gnu/13/include/g++-v13/ios:44, from /usr/lib/gcc/x86_64-pc-linux-gnu/13/include/g++-v13/ostream:40, from /usr/lib/gcc/x86_64-pc-linux-gnu/13/include/g++-v13/iostream:41, of module /usr/lib/gcc/x86_64-pc-linux-gnu/13/include/g++-v13/iostream, imported at hello.cpp:2: In member function =E2=80=98constexpr const std::basic_string_view<_CharT, _Traits>::value_type* std::basic_string_view<_CharT, _Traits>::data() const [with _CharT =3D char; _Traits =3D std::char_traits]=E2=80=99, inlined from =E2=80=98std::basic_ostream<_CharT, _Traits>& std::operator<<(basic_ostream<_CharT, _Traits>&, basic_string_view<_CharT, _Traits>) [with _CharT =3D char; _Traits =3D char_traits]=E2=80=99 at /usr/lib/gcc/x86_64-pc-linux-gnu/13/include/g++-v13/string_view:762:30, inlined from =E2=80=98void f(std::string_view)=E2=80=99 at hello.cpp:5:= 15: /usr/lib/gcc/x86_64-pc-linux-gnu/13/include/g++-v13/string_view:292:22: warning: =E2=80=98this=E2=80=99 is used uninitialized [-Wuninitialized] 292 | { return this->_M_str; } | ^~~~~~ In file included from hello.cpp:1: /usr/lib/gcc/x86_64-pc-linux-gnu/13/include/g++-v13/string_view: In function =E2=80=98void f(std::string_view)=E2=80=99: /usr/lib/gcc/x86_64-pc-linux-gnu/13/include/g++-v13/string_view:760:5: note: =E2=80=98this=E2=80=99 was declared here 760 | operator<<(basic_ostream<_CharT, _Traits>& __os, | ^~~~~~~~ $ ./hello Segmentation fault (core dumped) If I use optimization level zero, the problem goes away (both the segfault = and the =E2=80=9Cuninitialized=E2=80=9D warning). Likewise if I import both hea= ders rather than including one of them. But as far as I=E2=80=99m aware, I haven=E2=80=99t f= ound any indication that the stdlib is required to be either all-included or all-imported and n= ot a mix.=