[Bug c++/99965] segfault only happening with -O3
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99965 --- Comment #9 from Jakub Jelinek --- Note, even std::vector 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.
[Bug c++/99965] segfault only happening with -O3
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99965 --- Comment #8 from Andrew Pinski --- (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.
[Bug c++/99965] segfault only happening with -O3
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99965 --- Comment #7 from Juan Lucas Rey --- the thing is removing the vector m_vPointers makes it work. also this code works fine on clang.. why would it be misaligned?
[Bug c++/99965] segfault only happening with -O3
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99965 --- Comment #6 from Juan Lucas Rey --- I get the following with -fsanitize=alignment bug.cpp:29:21: runtime error: store to misaligned address 0x02249044 for type 'char *', which requires 8 byte alignment 0x02249044: 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
[Bug c++/99965] segfault only happening with -O3
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99965 Andrew Pinski changed: What|Removed |Added Status|WAITING |RESOLVED Resolution|--- |INVALID --- Comment #5 from Andrew Pinski --- (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(pBuf);
[Bug c++/99965] segfault only happening with -O3
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99965 --- Comment #4 from Juan Lucas Rey --- 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
[Bug c++/99965] segfault only happening with -O3
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99965 Jakub Jelinek changed: What|Removed |Added CC||jakub at gcc dot gnu.org --- Comment #3 from Jakub Jelinek --- Also, GCC 7.3 isn't supported anymore, only GCC 8+ is ATM.
[Bug c++/99965] segfault only happening with -O3
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99965 Andrew Pinski changed: What|Removed |Added Status|UNCONFIRMED |WAITING Ever confirmed|0 |1 Last reconfirmed||2021-04-07 --- Comment #2 from Andrew Pinski --- I think you are violating C alignment rules. Can you try adding -fsanitize=alignment ?
[Bug c++/99965] segfault only happening with -O3
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99965 --- Comment #1 from Juan Lucas Rey --- g++ --version g++ (GCC) 7.3.1 20180303 (Red Hat 7.3.1-5)