Fixed comparison RHS expression parsing
authorRobert Pengelly <robertapengelly@hotmail.com>
Tue, 8 Sep 2026 15:42:28 +0000 (16:42 +0100)
committerRobert Pengelly <robertapengelly@hotmail.com>
Tue, 8 Sep 2026 15:42:28 +0000 (16:42 +0100)
amd64.c
i386.c

diff --git a/amd64.c b/amd64.c
index 9cf3d8977d7413bf3e995cb0da1150c9d61ba8db..52c781112656d4cc6fa273ffc9e90b5b7954fa81 100644 (file)
--- a/amd64.c
+++ b/amd64.c
@@ -33626,7 +33626,26 @@ static int emit_statement_rhs_const32_to_rdx_if_possible (void) {
         if (current_integer_expr_is_foldable_now ()) {
             v = const64_from_current_foldable_expr ();
         } else {
+        
+            struct token *saved_tok = clone_current_token_now ();
+            enum token_kind next_kind;
+            
+            get_token ();
+            
+            next_kind = tok.kind;
+            unget_token (saved_tok);
+            
+            /*
+             * A leading constant may only be the first operand of the RHS.
+             * Leave expressions such as LIMIT - 1 to the normal expression
+             * parser instead of consuming LIMIT as the complete operand.
+             */
+            if (token_kind_is_binary_expression_operator_now (next_kind)) {
+                return 0;
+            }
+            
             v = const64_from_current_operand ();
+        
         }
         
         emit_statement_const32_to_rdx (v);
diff --git a/i386.c b/i386.c
index 7a086c07d6dcb07644536403103e3070e7599eeb..af240792ab1dec4514773229a75feaa52ee8461e 100644 (file)
--- a/i386.c
+++ b/i386.c
@@ -30931,7 +30931,26 @@ static int emit_statement_rhs_const32_to_edx_if_possible (void) {
         if (current_integer_expr_is_foldable_now ()) {
             v = const64_from_current_foldable_expr ();
         } else {
+        
+            struct token *saved_tok = clone_current_token_now ();
+            enum token_kind next_kind;
+            
+            get_token ();
+            
+            next_kind = tok.kind;
+            unget_token (saved_tok);
+            
+            /*
+             * A leading constant may only be the first operand of the RHS.
+             * Leave expressions such as LIMIT - 1 to the normal expression
+             * parser instead of consuming LIMIT as the complete operand.
+             */
+            if (token_kind_is_binary_expression_operator_now (next_kind)) {
+                return 0;
+            }
+            
             v = const64_from_current_operand ();
+        
         }
         
         emit_statement_const32_to_edx (v);