https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105100
Bug ID: 105100 Summary: Strange warning when modifying structures "writing 1 byte into a region of size 0" when compile with -O3 Product: gcc Version: 11.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: ercli at ucdavis dot edu Target Milestone: --- Created attachment 52715 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=52715&action=edit Preprocessor output that triggers the bug I am compiling a function that reads a byte array and converts it to structures. I find strange compiler warnings when using -O3 optimization. See attachment from line 10 for a minimize test case. My source code is named b.c, which does not contain any includes. The exact version of GCC: gcc (GCC) 11.2.1 20220127 (Red Hat 11.2.1-9) Also see compiler output below The system type: Fedora 35 Workstation, kernel 5.16.16-200.fc35.x86_64 The options given when GCC was configured/built: See compiler output below The complete command line that triggers the bug: gcc -v -save-temps -O3 -Wall -Werror -c -o b.o b.c The compiler output (error messages, warnings, etc.): Using built-in specs. COLLECT_GCC=gcc OFFLOAD_TARGET_NAMES=nvptx-none OFFLOAD_TARGET_DEFAULT=1 Target: x86_64-redhat-linux Configured with: ../configure --enable-bootstrap --enable-languages=c,c++,fortran,objc,obj-c++,ada,go,d,lto --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-gcc-major-version-only --with-linker-hash-style=gnu --enable-plugin --enable-initfini-array --with-isl=/builddir/build/BUILD/gcc-11.2.1-20220127/obj-x86_64-redhat-linux/isl-install --enable-offload-targets=nvptx-none --without-cuda-driver --enable-gnu-indirect-function --enable-cet --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux --with-build-config=bootstrap-lto --enable-link-serialization=1 Thread model: posix Supported LTO compression algorithms: zlib zstd gcc version 11.2.1 20220127 (Red Hat 11.2.1-9) (GCC) COLLECT_GCC_OPTIONS='-v' '-save-temps' '-O3' '-Wall' '-Werror' '-c' '-o' 'b.o' '-mtune=generic' '-march=x86-64' /usr/libexec/gcc/x86_64-redhat-linux/11/cc1 -E -quiet -v b.c -mtune=generic -march=x86-64 -Wall -Werror -O3 -fpch-preprocess -o b.i ignoring nonexistent directory "/usr/lib/gcc/x86_64-redhat-linux/11/include-fixed" ignoring nonexistent directory "/usr/lib/gcc/x86_64-redhat-linux/11/../../../../x86_64-redhat-linux/include" #include "..." search starts here: #include <...> search starts here: /usr/lib/gcc/x86_64-redhat-linux/11/include /usr/local/include /usr/include End of search list. COLLECT_GCC_OPTIONS='-v' '-save-temps' '-O3' '-Wall' '-Werror' '-c' '-o' 'b.o' '-mtune=generic' '-march=x86-64' /usr/libexec/gcc/x86_64-redhat-linux/11/cc1 -fpreprocessed b.i -quiet -dumpbase b.c -dumpbase-ext .c -mtune=generic -march=x86-64 -O3 -Wall -Werror -version -o b.s GNU C17 (GCC) version 11.2.1 20220127 (Red Hat 11.2.1-9) (x86_64-redhat-linux) compiled by GNU C version 11.2.1 20220127 (Red Hat 11.2.1-9), GMP version 6.2.0, MPFR version 4.1.0-p13, MPC version 1.2.1, isl version isl-0.18-GMP GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 GNU C17 (GCC) version 11.2.1 20220127 (Red Hat 11.2.1-9) (x86_64-redhat-linux) compiled by GNU C version 11.2.1 20220127 (Red Hat 11.2.1-9), GMP version 6.2.0, MPFR version 4.1.0-p13, MPC version 1.2.1, isl version isl-0.18-GMP GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 Compiler executable checksum: 8878ef997f8884938fae95d09b5e3a52 b.c: In function 'func': b.c:28:31: error: writing 1 byte into a region of size 0 [-Werror=stringop-overflow=] 28 | pb[i] = src[0]; | ~~~~~~^~~~~~~~ b.c:9:18: note: at offset 2 into destination object 'a' of size 2 9 | uint16_t a; | ^ b.c:28:31: error: writing 1 byte into a region of size 0 [-Werror=stringop-overflow=] 28 | pb[i] = src[0]; | ~~~~~~^~~~~~~~ b.c:9:18: note: at offset 3 into destination object 'a' of size 2 9 | uint16_t a; | ^ cc1: all warnings being treated as errors