Fix pointer arithmetic scaling with enclosing casts
authorRobert Pengelly <robertapengelly@hotmail.com>
Sun, 8 Nov 2026 05:32:10 +0000 (05:32 +0000)
committerRobert Pengelly <robertapengelly@hotmail.com>
Sun, 8 Nov 2026 05:32:10 +0000 (05:32 +0000)
amd64.c
i386.c

diff --git a/amd64.c b/amd64.c
index a24dc05bac3914b3cee582e71f18b11eda9c7f8d..c47ec4177f139631ed11124da1f530ff64a452aa 100644 (file)
--- 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 a61b3a996ab03d81b789e861dcbd4afb1769a8a6..be8295f45c0c138db02ad0b835b686783c72a336 100644 (file)
--- 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 ();