public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/99965] New: segfault only happening with -O3
@ 2021-04-07 20:32 juanlucasrey at gmail dot com
  2021-04-07 20:34 ` [Bug c++/99965] " juanlucasrey at gmail dot com
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: juanlucasrey at gmail dot com @ 2021-04-07 20:32 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 99965
           Summary: segfault only happening with -O3
           Product: gcc
           Version: 7.3.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: juanlucasrey at gmail dot com
  Target Milestone: ---

Created attachment 50526
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=50526&action=edit
file to reproduce

the following file runs fine with -O0, -O1 or -O2 but has a segmentation fault
when compiled with -O3

g++ bug.cpp -o bug -O3 && ./bug

I am executing this in a red hat docker container (if it matters)

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

* [Bug c++/99965] segfault only happening with -O3
  2021-04-07 20:32 [Bug c++/99965] New: segfault only happening with -O3 juanlucasrey at gmail dot com
@ 2021-04-07 20:34 ` juanlucasrey at gmail dot com
  2021-04-07 20:36 ` pinskia at gcc dot gnu.org
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: juanlucasrey at gmail dot com @ 2021-04-07 20:34 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Juan Lucas Rey <juanlucasrey at gmail dot com> ---
g++ --version
g++ (GCC) 7.3.1 20180303 (Red Hat 7.3.1-5)

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

* [Bug c++/99965] segfault only happening with -O3
  2021-04-07 20:32 [Bug c++/99965] New: segfault only happening with -O3 juanlucasrey at gmail dot com
  2021-04-07 20:34 ` [Bug c++/99965] " juanlucasrey at gmail dot com
@ 2021-04-07 20:36 ` pinskia at gcc dot gnu.org
  2021-04-07 20:39 ` jakub at gcc dot gnu.org
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-04-07 20:36 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |WAITING
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2021-04-07

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
I think you are violating C alignment rules.
Can you try adding -fsanitize=alignment ?

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

* [Bug c++/99965] segfault only happening with -O3
  2021-04-07 20:32 [Bug c++/99965] New: segfault only happening with -O3 juanlucasrey at gmail dot com
  2021-04-07 20:34 ` [Bug c++/99965] " juanlucasrey at gmail dot com
  2021-04-07 20:36 ` pinskia at gcc dot gnu.org
@ 2021-04-07 20:39 ` jakub at gcc dot gnu.org
  2021-04-07 21:02 ` juanlucasrey at gmail dot com
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: jakub at gcc dot gnu.org @ 2021-04-07 20:39 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jakub at gcc dot gnu.org

--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Also, GCC 7.3 isn't supported anymore, only GCC 8+ is ATM.

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

* [Bug c++/99965] segfault only happening with -O3
  2021-04-07 20:32 [Bug c++/99965] New: segfault only happening with -O3 juanlucasrey at gmail dot com
                   ` (2 preceding siblings ...)
  2021-04-07 20:39 ` jakub at gcc dot gnu.org
@ 2021-04-07 21:02 ` juanlucasrey at gmail dot com
  2021-04-07 21:08 ` pinskia at gcc dot gnu.org
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: juanlucasrey at gmail dot com @ 2021-04-07 21:02 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Juan Lucas Rey <juanlucasrey at gmail dot com> ---
I get the error "cannot find -lubsan" with -fsanitize=alignment



g++ bug.cpp -o bug -O2 -ftree-loop-vectorize -fvect-cost-model && ./bug

this also reproduces the segfault

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

* [Bug c++/99965] segfault only happening with -O3
  2021-04-07 20:32 [Bug c++/99965] New: segfault only happening with -O3 juanlucasrey at gmail dot com
                   ` (3 preceding siblings ...)
  2021-04-07 21:02 ` juanlucasrey at gmail dot com
@ 2021-04-07 21:08 ` pinskia at gcc dot gnu.org
  2021-04-07 21:09 ` juanlucasrey at gmail dot com
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-04-07 21:08 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|WAITING                     |RESOLVED
         Resolution|---                         |INVALID

--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Juan Lucas Rey from comment #4)
> I get the error "cannot find -lubsan" with -fsanitize=alignment

You must not have all of the correct packages install; not a GCC issue.

> 
> g++ bug.cpp -o bug -O2 -ftree-loop-vectorize -fvect-cost-model && ./bug
> 
> this also reproduces the segfault

Yes so this is an alignment issue.  NOT a GCC bug.

Check to make sure you have the correct alignment here:
    char** ppArray0 = reinterpret_cast<char**>(pBuf);

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

* [Bug c++/99965] segfault only happening with -O3
  2021-04-07 20:32 [Bug c++/99965] New: segfault only happening with -O3 juanlucasrey at gmail dot com
                   ` (4 preceding siblings ...)
  2021-04-07 21:08 ` pinskia at gcc dot gnu.org
@ 2021-04-07 21:09 ` juanlucasrey at gmail dot com
  2021-04-07 21:11 ` juanlucasrey at gmail dot com
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: juanlucasrey at gmail dot com @ 2021-04-07 21:09 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from Juan Lucas Rey <juanlucasrey at gmail dot com> ---
I get the following with -fsanitize=alignment

bug.cpp:29:21: runtime error: store to misaligned address 0x000002249044 for
type 'char *', which requires 8 byte alignment
0x000002249044: note: pointer points here
  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  00
00 00 00 00 00 00 00

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

* [Bug c++/99965] segfault only happening with -O3
  2021-04-07 20:32 [Bug c++/99965] New: segfault only happening with -O3 juanlucasrey at gmail dot com
                   ` (5 preceding siblings ...)
  2021-04-07 21:09 ` juanlucasrey at gmail dot com
@ 2021-04-07 21:11 ` juanlucasrey at gmail dot com
  2021-04-07 21:19 ` pinskia at gcc dot gnu.org
  2021-04-08 10:19 ` jakub at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: juanlucasrey at gmail dot com @ 2021-04-07 21:11 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from Juan Lucas Rey <juanlucasrey at gmail dot com> ---
the thing is removing the vector m_vPointers makes it work. also this code
works fine on clang.. why would it be misaligned?

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

* [Bug c++/99965] segfault only happening with -O3
  2021-04-07 20:32 [Bug c++/99965] New: segfault only happening with -O3 juanlucasrey at gmail dot com
                   ` (6 preceding siblings ...)
  2021-04-07 21:11 ` juanlucasrey at gmail dot com
@ 2021-04-07 21:19 ` pinskia at gcc dot gnu.org
  2021-04-08 10:19 ` jakub at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-04-07 21:19 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #8 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Juan Lucas Rey from comment #7)
> the thing is removing the vector m_vPointers makes it work.

Just by accident.

> also this code works fine on clang.. why would it be misaligned?

Because pBuf only needs to be aligned to 1 so in this case it is aligned to 8,
and adding size_0 (10*2=20=4*5) makes it aigned to only 4.

If you want aligned storage, use std::aligned_storage instead.

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

* [Bug c++/99965] segfault only happening with -O3
  2021-04-07 20:32 [Bug c++/99965] New: segfault only happening with -O3 juanlucasrey at gmail dot com
                   ` (7 preceding siblings ...)
  2021-04-07 21:19 ` pinskia at gcc dot gnu.org
@ 2021-04-08 10:19 ` jakub at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: jakub at gcc dot gnu.org @ 2021-04-08 10:19 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #9 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Note, even std::vector<char> isn't guaranteed to align for the pointer types,
but usually will, but even when you ensure the start is aligned, the pointer
arithmetics you do afterwards needs to ensure that it is aligned too.

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

end of thread, other threads:[~2021-04-08 10:19 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-07 20:32 [Bug c++/99965] New: segfault only happening with -O3 juanlucasrey at gmail dot com
2021-04-07 20:34 ` [Bug c++/99965] " juanlucasrey at gmail dot com
2021-04-07 20:36 ` pinskia at gcc dot gnu.org
2021-04-07 20:39 ` jakub at gcc dot gnu.org
2021-04-07 21:02 ` juanlucasrey at gmail dot com
2021-04-07 21:08 ` pinskia at gcc dot gnu.org
2021-04-07 21:09 ` juanlucasrey at gmail dot com
2021-04-07 21:11 ` juanlucasrey at gmail dot com
2021-04-07 21:19 ` pinskia at gcc dot gnu.org
2021-04-08 10:19 ` jakub 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).