public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/110861] New: Bad codegen leading to runtime segfault when mixing import and #include
@ 2023-07-31 15:02 headch at gmail dot com
  2023-07-31 15:05 ` [Bug c++/110861] " headch at gmail dot com
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: headch at gmail dot com @ 2023-07-31 15:02 UTC (permalink / raw)
  To: gcc-bugs

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

            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 <string_view>
import <iostream>;

void f(std::string_view sv) {
        std::cout << sv;
}

int main() {
        f("hello\n");
}


$ g++-13 -O1 -Wall -Wextra -c -std=c++20 -x c++-system-header -fmodules-ts
-fmodule-header=system iostream


$ g++-13 -std=c++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:40,
                 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 ‘constexpr const std::basic_string_view<_CharT,
_Traits>::value_type* std::basic_string_view<_CharT, _Traits>::data() const
[with _CharT = char; _Traits = std::char_traits<char>]’,
    inlined from ‘std::basic_ostream<_CharT, _Traits>&
std::operator<<(basic_ostream<_CharT, _Traits>&, basic_string_view<_CharT,
_Traits>) [with _CharT = char; _Traits = char_traits<char>]’ at
/usr/lib/gcc/x86_64-pc-linux-gnu/13/include/g++-v13/string_view:762:30,
    inlined from ‘void f(std::string_view)’ at hello.cpp:5:15:
/usr/lib/gcc/x86_64-pc-linux-gnu/13/include/g++-v13/string_view:292:22:
warning: ‘this’ 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
‘void f(std::string_view)’:
/usr/lib/gcc/x86_64-pc-linux-gnu/13/include/g++-v13/string_view:760:5: note:
‘this’ 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 “uninitialized” warning). Likewise if I import both headers rather than
including one of them. But as far as I’m aware, I haven’t found any indication
that the stdlib is required to be either all-included or all-imported and not a
mix.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug c++/110861] Bad codegen leading to runtime segfault when mixing import and #include
  2023-07-31 15:02 [Bug c++/110861] New: Bad codegen leading to runtime segfault when mixing import and #include headch at gmail dot com
@ 2023-07-31 15:05 ` headch at gmail dot com
  2024-03-06 16:47 ` ppalka at gcc dot gnu.org
  2024-03-06 18:01 ` ppalka at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: headch at gmail dot com @ 2023-07-31 15:05 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Christopher Head <headch at gmail dot com> ---
Note that I ran into this while trying to find a small repro case for the same
symptoms (uninitialized “this” and segfault using a string_view) in a larger
project, where I originally saw the same thing happen while only importing
stdlib headers, not including any of them, and eventually made this as a
smaller example.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug c++/110861] Bad codegen leading to runtime segfault when mixing import and #include
  2023-07-31 15:02 [Bug c++/110861] New: Bad codegen leading to runtime segfault when mixing import and #include headch at gmail dot com
  2023-07-31 15:05 ` [Bug c++/110861] " headch at gmail dot com
@ 2024-03-06 16:47 ` ppalka at gcc dot gnu.org
  2024-03-06 18:01 ` ppalka at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: ppalka at gcc dot gnu.org @ 2024-03-06 16:47 UTC (permalink / raw)
  To: gcc-bugs

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

Patrick Palka <ppalka at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ppalka at gcc dot gnu.org
         Resolution|---                         |FIXED
             Status|UNCONFIRMED                 |RESOLVED
   Target Milestone|---                         |14.0
           See Also|                            |https://gcc.gnu.org/bugzill
                   |                            |a/show_bug.cgi?id=112588

--- Comment #2 from Patrick Palka <ppalka at gcc dot gnu.org> ---
This is fixed for GCC 14 since the fix r14-8196 for PR112588.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug c++/110861] Bad codegen leading to runtime segfault when mixing import and #include
  2023-07-31 15:02 [Bug c++/110861] New: Bad codegen leading to runtime segfault when mixing import and #include headch at gmail dot com
  2023-07-31 15:05 ` [Bug c++/110861] " headch at gmail dot com
  2024-03-06 16:47 ` ppalka at gcc dot gnu.org
@ 2024-03-06 18:01 ` ppalka at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: ppalka at gcc dot gnu.org @ 2024-03-06 18:01 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110861
Bug 110861 depends on bug 99569, which changed state.

Bug 99569 Summary: segfault when running a module
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99569

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |DUPLICATE

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-03-06 18:01 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-31 15:02 [Bug c++/110861] New: Bad codegen leading to runtime segfault when mixing import and #include headch at gmail dot com
2023-07-31 15:05 ` [Bug c++/110861] " headch at gmail dot com
2024-03-06 16:47 ` ppalka at gcc dot gnu.org
2024-03-06 18:01 ` ppalka at gcc dot gnu.org

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).