From: Robert Pengelly Date: Wed, 15 Jul 2026 23:43:55 +0000 (+0100) Subject: More sizeof fixes X-Git-Url: https://git.candlhat.org/?a=commitdiff_plain;h=1adc79b5a13451011ccd7fb0ff4a403448dab954;p=scc.git More sizeof fixes --- 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 {