From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 4D037385802E; Tue, 19 Jan 2021 20:18:46 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4D037385802E From: "foss at grueninger dot de" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/98753] New: -Wfree-nonheap-object on Bison generated code Date: Tue, 19 Jan 2021 20:18:46 +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.0 X-Bugzilla-Keywords: diagnostic X-Bugzilla-Severity: normal X-Bugzilla-Who: foss at grueninger 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 keywords bug_severity priority component assigned_to reporter target_milestone cf_gccbuild 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, 19 Jan 2021 20:18:46 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D98753 Bug ID: 98753 Summary: -Wfree-nonheap-object on Bison generated code Product: gcc Version: 11.0 Status: UNCONFIRMED Keywords: diagnostic Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: foss at grueninger dot de Target Milestone: --- Build: 11.0.0 20210114 (experimental) [revision 08a4adcf2b6ded2fea97195c715757df61a23395] (SUSE Linux) Created attachment 50005 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=3D50005&action=3Dedit C++ file generated by Bison While compiling CMake with GCC 11.0, I spot some -Wfree-nonheap-object warnings. These came from files generated by Bison. I regenerated the C++ f= iles with the latest GNU Bison release and the problem persisted. So I asked on = the Bison user list and one of the developers claims, that Bison is right. I don't know whether it is a false positive or whether Bison has a bug. 1. Attached is the C++ file generated by Bison (cmCommandArgumentParser.cxx). 2. The warning I get from G++: [ 54%] Building CXX object Source/CMakeFiles/CMakeLib.dir/LexerParser/cmCommandArgumentParser.cxx.o cmCommandArgumentParser.cxx: In function =E2=80=98int cmCommandArgument_yyparse(yyscan_t)=E2=80=99: cmCommandArgumentParser.cxx:1838:18: warning: =E2=80=98void free(void*)=E2= =80=99 called on unallocated object =E2=80=98yyssa=E2=80=99 [-Wfree-nonheap-object] cmCommandArgumentParser.cxx:1203:16: note: declared here 3. The explanation / reduced code from one of the Bison developers, why the co= de is correct: > GCC 11 is wrong here. The full story (taken from your file) is: > >> // Create. >> yy_state_t yyssa[YYINITDEPTH]; >> yy_state_t *yyss =3D yyssa; >> [...] >> // Grow. >> yystacksize *=3D 2; >> { >> yy_state_t *yyss1 =3D yyss; >> union yyalloc *yyptr =3D >> YY_CAST (union yyalloc *, >> YYSTACK_ALLOC (YY_CAST (YYSIZE_T, YYSTACK_BYTES=20 >> (yystacksize)))); >> if (! yyptr) >> goto yyexhaustedlab; >> YYSTACK_RELOCATE (yyss_alloc, yyss); >> if (yyss1 !=3D yyssa) >> YYSTACK_FREE (yyss1); >> } >> [...] >> // Clean up >> if (yyss !=3D yyssa) >> YYSTACK_FREE (yyss); > > Or, in words, we use a stack-allocated stack until it's too small and > then we use a heap-allocated stack, and in that case, and that case > only, we free it at the end. Said another way: we never ever call > free(yyssa). >=20 > So GCC's warning is a false positive. Source: https://lists.gnu.org/archive/html/help-bison/2021-01/msg00021.html 4. My GCC version is: > gcc-11 -v Using built-in specs. COLLECT_GCC=3Dgcc-11 COLLECT_LTO_WRAPPER=3D/usr/lib64/gcc/x86_64-suse-linux/11/lto-wrapper OFFLOAD_TARGET_NAMES=3Dnvptx-none:amdgcn-amdhsa OFFLOAD_TARGET_DEFAULT=3D1 Target: x86_64-suse-linux Configured with: ../configure --prefix=3D/usr --infodir=3D/usr/share/info --mandir=3D/usr/share/man --libdir=3D/usr/lib64 --libexecdir=3D/usr/lib64 --enable-languages=3Dc,c++,objc,fortran,obj-c++,ada,go,d --enable-offload-targets=3Dnvptx-none,amdgcn-amdhsa, --without-cuda-driver --enable-checking=3Drelease --disable-werror --with-gxx-include-dir=3D/usr/include/c++/11 --enable-ssp --disable-libssp --disable-libvtv --enable-cet=3Dauto --disable-libcc1 --disable-plugin --with-bugurl=3Dhttps://bugs.opensuse.org/ --with-pkgversion=3D'SUSE Linux' --with-slibdir=3D/lib64 --with-system-zlib --enable-libstdcxx-allocator=3Dn= ew --disable-libstdcxx-pch --enable-libphobos --enable-version-specific-runtime-libs --with-gcc-major-version-only --enable-linker-build-id --enable-linux-futex --enable-gnu-indirect-function --program-suffix=3D-11 --without-system-libunwind --enable-multilib --with-arch-32=3Dx86-64 --with-tune=3Dgeneric --build=3Dx86_64-suse-linux --host=3Dx86_64-suse-linux Thread model: posix Supported LTO compression algorithms: zlib gcc version 11.0.0 20210114 (experimental) [revision 08a4adcf2b6ded2fea97195c715757df61a23395] (SUSE Linux)=