From 783d24f873783127b2a08b854006608c5d3e8f42 Mon Sep 17 00:00:00 2001 From: Robert Pengelly Date: Fri, 4 Sep 2026 10:37:06 +0100 Subject: [PATCH] Fixed repeated pointer dereferences --- amd64.c | 17 +++++++++++++++++ i386.c | 17 +++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/amd64.c b/amd64.c index 7177be4..8dc62d1 100644 --- a/amd64.c +++ b/amd64.c @@ -12764,6 +12764,7 @@ static void emit_store_floating_member_to_addr_reg_now (const char *addr_reg, in static void emit_load_floating_rhs_expression_now (int result_size); static void emit_load_assignment_rhs_to_reg (const char *reg); +static int source_starts_double_deref_at_now (const char *p); static int emit_load_deref_assignment_expression_to_reg_now (const char *reg); static int emit_statement_rhs_const32_to_rdx_if_possible (void); @@ -13092,6 +13093,22 @@ static void emit_load_assignment_rhs_to_pair (const char *lo, const char *hi) { } + /* + * Repeated unary dereference belongs to the normal scalar operand parser. + * Let it consume the complete chain (*p, **pp, ***ppp, ...), then widen + * the resulting scalar value for the pair expression. The old pair path + * consumed one '*' itself and therefore required the following token to be + * an identifier, rejecting every repeated-dereference expression. + */ + if (tok.kind == TOK_STAR && source_starts_double_deref_at_now (tok.caret)) { + + emit_load_assignment_rhs_to_reg (lo); + + emit_extend_pair_high_from_low (lo, hi, DATA_INT & 0x1f, 1); + return; + + } + if (tok.kind == TOK_STAR) { char *name; diff --git a/i386.c b/i386.c index 8556587..d24d3b4 100644 --- a/i386.c +++ b/i386.c @@ -11356,6 +11356,7 @@ static void emit_store_floating_member_to_addr_reg_now (const char *addr_reg, in static void emit_load_floating_rhs_expression_now (int result_size); static void emit_load_assignment_rhs_to_reg (const char *reg); +static int source_starts_double_deref_at_now (const char *p); static int emit_load_deref_assignment_expression_to_reg_now (const char *reg); static int emit_statement_rhs_const32_to_edx_if_possible (void); @@ -11644,6 +11645,22 @@ static void emit_load_assignment_rhs_to_pair (const char *lo, const char *hi) { } + /* + * Repeated unary dereference belongs to the normal scalar operand parser. + * Let it consume the complete chain (*p, **pp, ***ppp, ...), then widen + * the resulting scalar value for the pair expression. The old pair path + * consumed one '*' itself and therefore required the following token to be + * an identifier, rejecting every repeated-dereference expression. + */ + if (tok.kind == TOK_STAR && source_starts_double_deref_at_now (tok.caret)) { + + emit_load_assignment_rhs_to_reg (lo); + + emit_extend_pair_high_from_low (lo, hi, DATA_INT & 0x1f, rhs_last_scalar_is_unsigned >= 0 ? rhs_last_scalar_is_unsigned : 0); + return; + + } + if (tok.kind == TOK_STAR) { char *name; -- 2.34.1