More sizeof fixes
authorRobert Pengelly <robertapengelly@hotmail.com>
Wed, 15 Jul 2026 23:43:55 +0000 (00:43 +0100)
committerRobert Pengelly <robertapengelly@hotmail.com>
Wed, 15 Jul 2026 23:43:55 +0000 (00:43 +0100)
amd64.c
i386.c

diff --git a/amd64.c b/amd64.c
index 1c2768009fc73e16ed86b111096c2861d80855f4..ca75b133c453fcf6f4f91863e0c0b8cb262e4814 100644 (file)
--- 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 66a8773b2ffc5c0b3b204bb045683a8dce8ddd89..67e82f937b6ac5ba0b38e3d160d8b73ab44d27c6 100644 (file)
--- 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 {