[Bug c++/106092] New: Bogus -Wfree-nonheap-object

lavr at ncbi dot nlm.nih.gov gcc-bugzilla@gcc.gnu.org
Sun Jun 26 20:16:03 GMT 2022


            Bug ID: 106092
           Summary: Bogus -Wfree-nonheap-object
           Product: gcc
           Version: 11.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: lavr at ncbi dot nlm.nih.gov
  Target Milestone: ---

I got the following report from the compilation:

In file included from /home/ANTON/cxx/src/util/qparse/parser.cpp:352:
query_parser_bison.tab.c: In function ‘int ncbi_q_parse(void*)’:
query_parser_bison.tab.c:2354:18: warning: ‘void free(void*)’ called on
unallocated object ‘yyssa’ [-Wfree-nonheap-object]
In file included from /home/ANTON/cxx/src/util/qparse/parser.cpp:352:
query_parser_bison.tab.c:1351:18: note: declared here

The thing is, the code which is "blamed", looks like this (line numbers on):

   2353   if (yyss != yyssa)
   2354     YYSTACK_FREE (yyss);

which obviously tells NOT to free if the "yyss" is the same as "yyssa"...
So it's unclear from which context GCC "figured" that yyssa is going to be

The declarations look like this:

   1350     /* The state stack.  */
   1351     yytype_int16 yyssa[YYINITDEPTH];
   1352     yytype_int16 *yyss;
   1353     yytype_int16 *yyssp;

   1384   yyss = yyssa;

so at some point, yyss gets assigned with yyssa.  But then again, the code
instructs exactly NOT to free, in this case.  There's nothing to warn about.

More information about the Gcc-bugs mailing list