From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id CFBAA3945C3F; Tue, 29 Mar 2022 18:31:53 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CFBAA3945C3F From: "ercli at ucdavis dot edu" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/105100] New: Strange warning when modifying structures "writing 1 byte into a region of size 0" when compile with -O3 Date: Tue, 29 Mar 2022 18:31:53 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c X-Bugzilla-Version: 11.2.1 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: ercli at ucdavis dot edu X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone attachments.created Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 29 Mar 2022 18:31:53 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D105100 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=3D52715&action=3Dedit 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 nam= ed 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=3Dgcc OFFLOAD_TARGET_NAMES=3Dnvptx-none OFFLOAD_TARGET_DEFAULT=3D1 Target: x86_64-redhat-linux Configured with: ../configure --enable-bootstrap --enable-languages=3Dc,c++,fortran,objc,obj-c++,ada,go,d,lto --prefix=3D/usr --mandir=3D/usr/share/man --infodir=3D/usr/share/info --with-bugurl=3Dhttp://bugzilla.redhat.com/bugzilla --enable-shared --enable-threads=3Dposix --enable-checking=3Drelease --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=3Dgnu --enable-plugin --enable-initfini-array --with-isl=3D/builddir/build/BUILD/gcc-11.2.1-20220127/obj-x86_64-redhat-li= nux/isl-install --enable-offload-targets=3Dnvptx-none --without-cuda-driver --enable-gnu-indirect-function --enable-cet --with-tune=3Dgeneric --with-arch_32=3Di686 --build=3Dx86_64-redhat-linux --with-build-config=3Dbootstrap-lto --enable-link-serialization=3D1 Thread model: posix Supported LTO compression algorithms: zlib zstd gcc version 11.2.1 20220127 (Red Hat 11.2.1-9) (GCC)=20 COLLECT_GCC_OPTIONS=3D'-v' '-save-temps' '-O3' '-Wall' '-Werror' '-c' '-o' = 'b.o' '-mtune=3Dgeneric' '-march=3Dx86-64' /usr/libexec/gcc/x86_64-redhat-linux/11/cc1 -E -quiet -v b.c -mtune=3Dgene= ric -march=3Dx86-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/includ= e" #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=3D'-v' '-save-temps' '-O3' '-Wall' '-Werror' '-c' '-o' = 'b.o' '-mtune=3Dgeneric' '-march=3Dx86-64' /usr/libexec/gcc/x86_64-redhat-linux/11/cc1 -fpreprocessed b.i -quiet -dumpbase b.c -dumpbase-ext .c -mtune=3Dgeneric -march=3Dx86-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-lin= ux) 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=3D100 --param ggc-min-heapsize=3D131= 072 GNU C17 (GCC) version 11.2.1 20220127 (Red Hat 11.2.1-9) (x86_64-redhat-lin= ux) 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=3D100 --param ggc-min-heapsize=3D131= 072 Compiler executable checksum: 8878ef997f8884938fae95d09b5e3a52 b.c: In function 'func': b.c:28:31: error: writing 1 byte into a region of size 0 [-Werror=3Dstringop-overflow=3D] 28 | pb[i] =3D 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=3Dstringop-overflow=3D] 28 | pb[i] =3D 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=