https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105346
Bug ID: 105346
Summary: -Wno-free-nonheap-object false positive (on
Bison-generated grammar code)
Product: gcc
Version: 11.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: tim.vanholder at anubex dot com
Target Milestone: ---
Bison grammars (can) include code like
/* The state stack: array, bottom, top. */
yy_state_t yyssa[YYINITDEPTH];
yy_state_t *yyss = yyssa;
yy_state_t *yyssp = yyss;
... (code that may allocate a larger stack if needed, in which case `yyss` and
`yyssp` get repointed)
#ifndef yyoverflow
if (yyss != yyssa)
YYSTACK_FREE (yyss);
#endif
(with YYSTACK_FREE() expanding to free()).
For this gcc (Debian 11.2.0-19) 11.2.0 is reporting (with -Werror):
Linux/DML-grammar.cc:13901:18: error: ‘void free(void*)’ called on unallocated
object ‘yyssa’ [-Werror=free-nonheap-object]
13901 | YYSTACK_FREE (yyss);
Linux/DML-grammar.cc:5609:16: note: declared here
5609 | yy_state_t yyssa[YYINITDEPTH];
| ^~~~~
So it is tracing yyss to yyssa from its declaration, but is apparently not
seeing that there is an explicit test that yyss is not equal to yyssa around
the free.
(I'd test with a more recent version, but this is what I have available.)