From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 4B7AF3858D33; Wed, 11 Jan 2023 00:18:25 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4B7AF3858D33 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1673396305; bh=TMdLUz52hCY4KrGp9vjfKsfLukqfSkMxNx4JTCNX/BA=; h=From:To:Subject:Date:From; b=BGBA16SGCnZv1qcgdXjz3IbIzrmbkQSTd18MfRy9oD/nSC9NkcshJzQepZ41lYtV5 2EdZSyq+2ElS41H3GTRHml+5sxqmZMUJfpuWNDIw8irxetb61ojZMgGj9N67fx11sO +CToELJMWMs2tY5U7uNmvkBO3t+j65tYwOV/zfhI= From: "BenWiederhake.GitHub at gmx dot de" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/108366] New: [12/13 Regression] Spurious stringop overflow, possibly alias-related Date: Wed, 11 Jan 2023 00:18:16 +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: 12.2.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: BenWiederhake.GitHub at gmx dot de 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 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D108366 Bug ID: 108366 Summary: [12/13 Regression] Spurious stringop overflow, possibly alias-related Product: gcc Version: 12.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: BenWiederhake.GitHub at gmx dot de Target Milestone: --- Created attachment 54241 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=3D54241&action=3Dedit Minimal C++ file that reproduces the bug This seems similar but different from #107852. Starting with gcc 12 and continuing into the current trunk (git aa966d54ee4= ), the compiler emits a stringop overflow warning. In addition to the attachment: https://godbolt.org/z/3xorbqsha I would expect either of the following behaviors: - In line 20 (marked with "// !!!"), the compiler sees that even if `new` returned a nullptr for any reason, if execution continues in the make_vecto= r() function, it can now assume that new_buffer is non-null, and therefore mems= et is safe. - Alternatively, if the compiler cannot deduce that, then the warning should not be generated, since the compiler cannot now what pointer will be return= ed by data(). gcc trunk (git aa966d54ee4) =E2=86=92 spurious warning gcc 12.2.0 (Debian 12.2.0-13) =E2=86=92 spurious warning gcc 11.3.0 (Debian 11.3.0-10) =E2=86=92 no warning gcc 10.4.0 (Debian 10.4.0-6) =E2=86=92 no warning clang 13 and 14 =E2=86=92 no warning system type: Debian testing, x86_64 options during configure: Debian gcc reports: ../src/configure -v --with-pkgversion=3D'Debian 12.2.0-= 13' --with-bugurl=3Dfile:///usr/share/doc/gcc-12/README.Bugs --enable-languages=3Dc,ada,c++,go,d,fortran,objc,obj-c++,m2 --prefix=3D/usr --with-gcc-major-version-only --program-suffix=3D-12 --program-prefix=3Dx86_64-linux-gnu- --enable-shared --enable-linker-build-= id --libexecdir=3D/usr/lib --without-included-gettext --enable-threads=3Dposix --libdir=3D/usr/lib --enable-nls --enable-clocale=3Dgnu --enable-libstdcxx-= debug --enable-libstdcxx-time=3Dyes --with-default-libstdcxx-abi=3Dnew --enable-gnu-unique-object --disable-vtable-verify --enable-plugin --enable-default-pie --with-system-zlib --enable-libphobos-checking=3Drelea= se --with-target-system-zlib=3Dauto --enable-objc-gc=3Dauto --enable-multiarch --disable-werror --enable-cet --with-arch-32=3Di686 --with-abi=3Dm64 --with-multilib-list=3Dm32,m64,mx32 --enable-multilib --with-tune=3Dgeneric --enable-offload-targets=3Dnvptx-none=3D/build/gcc-12-PBog5r/gcc-12-12.2.0/= debian/tmp-nvptx/usr,amdgcn-amdhsa=3D/build/gcc-12-PBog5r/gcc-12-12.2.0/deb= ian/tmp-gcn/usr --enable-offload-defaulted --without-cuda-driver --enable-checking=3Drelease --build=3Dx86_64-linux-gnu --host=3Dx86_64-linux-gnu --target=3Dx86_64-linu= x-gnu When I manually built it I used this: ../gcc-src/configure --enable-shared --disable-werror --enable-languages=3D= c,c++ --enable-default-pie --enable-lto --enable-threads=3Dposix --enable-initfini-array --with-linker-hash-style=3Dgnu --disable-multilib complete commandline that triggers the bug: g++ -O2 -o foo repro.cpp compiler error message: ``` In function =E2=80=98Vector make_vector()=E2=80=99, inlined from =E2=80=98int main()=E2=80=99 at repro.cpp:36:31: repro.cpp:27:11: warning: =E2=80=98void* memset(void*, int, size_t)=E2=80= =99 writing 128 bytes into a region of size 40 overflows the destination [-Wstringop-overflow=3D] 27 | memset(buffer.data(), 'A', new_size); | ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ repro.cpp: In function =E2=80=98int main()=E2=80=99: repro.cpp:36:10: note: destination object =E2=80=98actual=E2=80=99 of size = 40 36 | auto actual =3D make_vector(); | ^~~~~~ ``` preprocessed file (*.i*) that triggers the bug: See next comments, I can't figure out how to put more than one attachment in a single comment.=