You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Previously, the parser only handled simple identifier dereference (*var)
and would crash on complex expressions like *(ptr + offset). This change
extends the dereference operator handling to accept general expressions
in parentheses.
This enables compilation of previously failing patterns:
- *(p + 4) - direct offset
- *(p + i + 2) - variable in expression
- *(p + i * 2) - arithmetic in expression
It also handles consecutive asterisks ('**pp', '***ppp') by counting
dereference levels and applying them iteratively.
When expressions like arr[0] + arr[1] + arr[2] were parsed, the compiler
was incorrectly applying pointer arithmetic scaling to the values read
from the array elements, resulting in wrong calculations.
The issue was in read_lvalue() which was handling the '+' operator after
array indexing as if it were pointer arithmetic. After arr[0], we have
an integer value, not a pointer, so the '+' should be handled by the
expression parser, not by read_lvalue.
This fix adds a check to ensure pointer arithmetic handling only occurs
when we have a pointer/array that hasn't been dereferenced (i.e., when
lvalue->is_reference is false).
Test case that was failing:
int arr[3] = {10, 20, 12};
return arr[0] + arr[1] + arr[2]; // Was returning 26 instead of 42
0 commit comments