Skip to content

Commit

Permalink
Handle pointer arithmetics with function operands
Browse files Browse the repository at this point in the history
  • Loading branch information
fuhsnn committed Dec 28, 2024
1 parent ada543f commit 2a9c631
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -3383,6 +3383,11 @@ static Node *new_add(Node *lhs, Node *rhs, Token *tok) {
if (is_numeric(lhs->ty) && is_numeric(rhs->ty))
return new_binary(ND_ADD, lhs, rhs, tok);

if (lhs->ty->kind == TY_FUNC)
lhs = new_cast(lhs, pointer_to(lhs->ty));
if (rhs->ty->kind == TY_FUNC)
rhs = new_cast(rhs, pointer_to(rhs->ty));

Node **ofs = is_integer(lhs->ty) ? &lhs : is_integer(rhs->ty) ? &rhs : NULL;
Node *ptr = lhs->ty->base ? lhs : rhs->ty->base ? rhs : NULL;

Expand All @@ -3407,6 +3412,11 @@ static Node *new_sub(Node *lhs, Node *rhs, Token *tok) {
if (is_numeric(lhs->ty) && is_numeric(rhs->ty))
return new_binary(ND_SUB, lhs, rhs, tok);

if (lhs->ty->kind == TY_FUNC)
lhs = new_cast(lhs, pointer_to(lhs->ty));
if (rhs->ty->kind == TY_FUNC)
rhs = new_cast(rhs, pointer_to(rhs->ty));

// ptr - num
if (lhs->ty->base && is_integer(rhs->ty)) {
if (lhs->ty->base->kind == TY_VLA)
Expand Down

0 comments on commit 2a9c631

Please sign in to comment.