From 1adc79b5a13451011ccd7fb0ff4a403448dab954 Mon Sep 17 00:00:00 2001 From: Robert Pengelly Date: Thu, 16 Jul 2026 00:43:55 +0100 Subject: [PATCH] More sizeof fixes --- amd64.c | 20 ++++++++++++++++++++ i386.c | 20 ++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/amd64.c b/amd64.c index 1c27680..ca75b13 100644 --- a/amd64.c +++ b/amd64.c @@ -32141,6 +32141,16 @@ static int emit_statement_rhs_const32_to_rdx_if_possible (void) { if (token_is_const_condition_operand_now ()) { + /** + * A sizeof expression may continue with arithmetic, for example + * sizeof (array) / sizeof (array[0]). const64_from_current_operand() + * consumes only the leading sizeof operand, so leave all sizeof + * conditions to the normal expression emitter. + */ + if (token_is_sizeof_keyword ()) { + return 0; + } + if (current_integer_expr_is_foldable_now ()) { v = const64_from_current_foldable_expr (); } else { @@ -32812,6 +32822,16 @@ static int emit_statement_rhs_const32_or_enum_to_rdx_if_possible (void) { if (token_is_const_condition_operand_now ()) { + /** + * A sizeof expression may continue with arithmetic, for example + * sizeof (array) / sizeof (array[0]). const64_from_current_operand() + * consumes only the leading sizeof operand, so leave all sizeof + * conditions to the normal expression emitter. + */ + if (token_is_sizeof_keyword ()) { + return 0; + } + if (current_integer_expr_is_foldable_now ()) { v = const64_from_current_foldable_expr (); } else { diff --git a/i386.c b/i386.c index 66a8773..67e82f9 100644 --- a/i386.c +++ b/i386.c @@ -29478,6 +29478,16 @@ static int emit_statement_rhs_const32_to_edx_if_possible (void) { if (token_is_const_condition_operand_now ()) { + /** + * A sizeof expression may continue with arithmetic, for example + * sizeof (array) / sizeof (array[0]). const64_from_current_operand() + * consumes only the leading sizeof operand, so leave all sizeof + * conditions to the normal expression emitter. + */ + if (token_is_sizeof_keyword ()) { + return 0; + } + if (current_integer_expr_is_foldable_now ()) { v = const64_from_current_foldable_expr (); } else { @@ -30149,6 +30159,16 @@ static int emit_statement_rhs_const32_or_enum_to_edx_if_possible (void) { if (token_is_const_condition_operand_now ()) { + /** + * A sizeof expression may continue with arithmetic, for example + * sizeof (array) / sizeof (array[0]). const64_from_current_operand() + * consumes only the leading sizeof operand, so leave all sizeof + * conditions to the normal expression emitter. + */ + if (token_is_sizeof_keyword ()) { + return 0; + } + if (current_integer_expr_is_foldable_now ()) { v = const64_from_current_foldable_expr (); } else { -- 2.34.1