https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112442
Bug ID: 112442 Summary: Segfault from casting a ptr when using -O2 Product: gcc Version: 13.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: adam.andersson at elisapolystar dot com Target Milestone: --- Created attachment 56532 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=56532&action=edit Small testprogram that reproduces the issue I have attached a simple program that segfaults when compiling with GCC 13 and -O2 Compiled with: gcc -v -save-temps -O2 gcc-segfault.c How to reproduce: $ gcc -O2 a-gcc-segfault.i -o test && ./test Segmentation fault (core dumped) This does not happen in GCC 12 or earlier, or if I use -O1 or no optimization. Also doesnt happen if I remove the cast to unsigned char*, or if I inline the test-function. My system: Linux adam1 6.5.9-arch2-1 #1 SMP PREEMPT_DYNAMIC Thu, 26 Oct 2023 00:52:20 +0000 x86_64 GNU/Linux gcc version 13.2.1 20230801 (GCC)