From 8985d29e1e529ba555d946ed6d9e178be7a37713 Mon Sep 17 00:00:00 2001 From: Robert Pengelly Date: Sun, 8 Nov 2026 05:32:10 +0000 Subject: [PATCH] Fix pointer arithmetic scaling with enclosing casts --- amd64.c | 39 --------------------------------------- i386.c | 39 --------------------------------------- 2 files changed, 78 deletions(-) diff --git a/amd64.c b/amd64.c index a24dc05..c47ec41 100644 --- a/amd64.c +++ b/amd64.c @@ -28301,40 +28301,6 @@ static void emit_compare_rax_rdx_to_reg (enum token_kind op, const char *reg, in static int rhs_current_operand_is_unsigned_now (void); -static int source_lhs_has_char_pointer_cast_before_now (const char *p) { - - const char *q; - int limit = 160; - - if (!p) { - return 0; - } - - q = p; - - while (limit-- > 0 && q > tok.start) { - - q--; - - if (*q != '(') { - continue; - } - - if ((strncmp (q, "(char", 5) == 0 || strncmp (q, "(unsigned char", 14) == 0 || strncmp (q, "(signed char", 12) == 0) - && strchr (q, '*') && strchr (q, ')') && strchr (q, '*') < p && strchr (q, ')') < p) { - return 1; - } - - if (*q == ';' || *q == ',' || *q == '\n') { - break; - } - - } - - return 0; - -} - static int arithmetic_operator_precedence_now (enum token_kind op) { if (op == TOK_PIPE) { @@ -28430,11 +28396,6 @@ static int emit_load_assignment_binary_expression_prec_to_reg (const char *reg, lhs_pointer_depth = expr_pointer_depth; lhs_pointed_size = expr_pointed_size; - if ((op == TOK_PLUS || op == TOK_MINUS) && lhs_pointer_depth > 0 && - source_lhs_has_char_pointer_cast_before_now (tok.caret)) { - lhs_pointed_size = DATA_CHAR & 0x1f; - } - get_token (); rhs_is_unsigned = rhs_current_operand_is_unsigned_now (); diff --git a/i386.c b/i386.c index a61b3a9..be8295f 100644 --- a/i386.c +++ b/i386.c @@ -25816,40 +25816,6 @@ static void emit_compare_eax_edx_to_reg (enum token_kind op, const char *reg, in static int rhs_current_operand_is_unsigned_now (void); -static int source_lhs_has_char_pointer_cast_before_now (const char *p) { - - const char *q; - int limit = 160; - - if (!p) { - return 0; - } - - q = p; - - while (limit-- > 0 && q > tok.start) { - - q--; - - if (*q != '(') { - continue; - } - - if ((strncmp (q, "(char", 5) == 0 || strncmp (q, "(unsigned char", 14) == 0 || strncmp (q, "(signed char", 12) == 0) - && strchr (q, '*') && strchr (q, ')') && strchr (q, '*') < p && strchr (q, ')') < p) { - return 1; - } - - if (*q == ';' || *q == ',' || *q == '\n') { - break; - } - - } - - return 0; - -} - static int arithmetic_operator_precedence_now (enum token_kind op) { if (op == TOK_PIPE) { @@ -25959,11 +25925,6 @@ static int emit_load_assignment_binary_expression_prec_to_reg (const char *reg, lhs_pointer_depth = expr_pointer_depth; lhs_pointed_size = expr_pointed_size; - if ((op == TOK_PLUS || op == TOK_MINUS) && lhs_pointer_depth > 0 && - source_lhs_has_char_pointer_cast_before_now (tok.caret)) { - lhs_pointed_size = DATA_CHAR & 0x1f; - } - get_token (); rhs_is_unsigned = rhs_current_operand_is_unsigned_now (); -- 2.34.1