[Bug c/112442] Segfault from casting a ptr when using -O2

2023-11-09 Thread xry111 at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112442 --- Comment #10 from Xi Ruoyao --- (In reply to Adam Andersson from comment #9) > I was sure I had tried -fno-strict-aliasing without any difference, but I > guessed I messed up somehow. Sorry about that. > > Still, is it not strange that -Wall

[Bug c/112442] Segfault from casting a ptr when using -O2

2023-11-08 Thread adam.andersson at elisapolystar dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112442 --- Comment #9 from Adam Andersson --- I was sure I had tried -fno-strict-aliasing without any difference, but I guessed I messed up somehow. Sorry about that. Still, is it not strange that -Wall doesn't generate a warning about this then?

[Bug c/112442] Segfault from casting a ptr when using -O2

2023-11-08 Thread redi at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112442 --- Comment #8 from Jonathan Wakely --- The aliasing doesn't happen when writing to the array, it's when reading a char* value from an object of type unsigned char*. If you just passed the unsigned char* to memcpy instead of *(char**)&ptr it wo

[Bug c/112442] Segfault from casting a ptr when using -O2

2023-11-08 Thread xry111 at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112442 --- Comment #7 from Xi Ruoyao --- Note that in the "new bug" page, there is a red banner saying: Before reporting that GCC compiles your code incorrectly, compile it with gcc -Wall -Wextra and see whether this shows anything wrong with your cod

[Bug c/112442] Segfault from casting a ptr when using -O2

2023-11-08 Thread xry111 at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112442 Xi Ruoyao changed: What|Removed |Added Resolution|--- |INVALID Status|UNCONFIRMED

[Bug c/112442] Segfault from casting a ptr when using -O2

2023-11-08 Thread schwab--- via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112442 --- Comment #5 from Andreas Schwab --- warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing] 15 | test((char **)&ptr, "test!");

[Bug c/112442] Segfault from casting a ptr when using -O2

2023-11-08 Thread adam.andersson at elisapolystar dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112442 --- Comment #4 from Adam Andersson --- (In reply to Andrew Pinski from comment #3) > I am not 100% sure but there seems like some kind of aliasing issue going on. > > Basically you have a pointer to an `unsigned char` but writing it via a > poi

[Bug c/112442] Segfault from casting a ptr when using -O2

2023-11-08 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112442 --- Comment #3 from Andrew Pinski --- I am not 100% sure but there seems like some kind of aliasing issue going on. Basically you have a pointer to an `unsigned char` but writing it via a pointer to `char`. Yes writing to a type via `char` woul

[Bug c/112442] Segfault from casting a ptr when using -O2

2023-11-08 Thread redi at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112442 --- Comment #2 from Jonathan Wakely --- Looks like it doesn't always segfault, but the contents of the tmp buffer are incorrect (which might segfault, or might fail to print "test!").

[Bug c/112442] Segfault from casting a ptr when using -O2

2023-11-08 Thread adam.andersson at elisapolystar dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112442 --- Comment #1 from Adam Andersson --- Disregard my comment about it working GCC 12. In gcc version 12.3.0 (GCC) it does not work either.