-
-
Notifications
You must be signed in to change notification settings - Fork 34
Open
Description
PackCC in some cases generates parser code with unused variables. This might trigger warnings/errors (depending on compiler options used) in code that uses the parser.
Simple grammar to reproduce the issue:
X <- ("A" / .*)+
When processed and compiled, it returns warning:
$ packcc -o parser test.peg
$ gcc -Wall -Werror parser.c -o parser
parser.c: In function ‘pcc_evaluate_rule_X’:
parser.c:1224:26: error: unused variable ‘n’ [-Werror=unused-variable]
1224 | const size_t n = chunk->thunks.n;
| ^
cc1: all warnings being treated as errors
The generated code looks like this:
static pcc_thunk_chunk_t *pcc_evaluate_rule_X(pcc_context_t *ctx) {
pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx);
chunk->pos = ctx->cur;
PCC_DEBUG(ctx->auxil, PCC_DBG_EVALUATE, "X", ctx->level, chunk->pos, (ctx->buffer.p + chunk->pos), (ctx->buffer.n - chunk->pos));
ctx->level++;
{
const size_t p0 = ctx->cur;
const size_t n0 = chunk->thunks.n;
int i;
for (i = 0;; i++) {
const size_t p = ctx->cur;
const size_t n = chunk->thunks.n;
{
MARK_VAR_AS_USED
const size_t p = ctx->cur;
MARK_VAR_AS_USED
const size_t n = chunk->thunks.n;
...It seems that there are some situations where the MARK_VAR_AS_USED is not generated.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels