From: Robert Pengelly Date: Tue, 8 Sep 2026 15:42:28 +0000 (+0100) Subject: Fixed comparison RHS expression parsing X-Git-Url: https://git.candlhat.org/?a=commitdiff_plain;h=16d7747e34202d2af0347e47ba9829a51b3426b5;p=scc.git Fixed comparison RHS expression parsing --- diff --git a/amd64.c b/amd64.c index 9cf3d89..52c7811 100644 --- 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 7a086c0..af24079 100644 --- 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);